| 发表于:2007-04-19 21:18:10 楼主 |
//filename: people_test.java //定义people类 class people{ public people(){ height = 0; weight = 0; } public double height,weight; public void speak_hello(){ system.out.println( "hello! "); } public void average_height(){ system.out.println(height); } public void average_weight(){ system.out.println(weight); } } //定义china_people class china_people extends people{ public void china_gongfu(){ system.out.println( "坐如钟,站如松,睡如弓 "); } public void speak_hello(){ system.out.println( "你好,吃饭了吗 "); } public void average_height(){ this.height = 173.0; system.out.println( "中国人的平均身高: "+height+ "厘米 "); } public void average_weight(){ this.weight = 67.34; system.out.println( "中国人的平均体重: "+weight+ "公斤 "); } } //定义american_people class american_people extends people{ public void american_boxing(){ system.out.println( "直拳、钩拳 "); } public void speak_hello(){ system.out.println( "how do you do ! "); } public void average_height(){ this.height = 188.0; system.out.println( "american average height: "+height+ " cm "); } public void average_weight(){ this.weight = 80.23; system.out.println( "american average weight: "+weight+ " kg "); } } //定义beijing_people class beijing_people extends people{ public void beijin_opera(){ system.out.println( "京剧术语 "); } public void speak_hello(){ system.out.println( "您好 "); } public void average_height(){ this.height = 176.0; system.out.println( "北京人的平均身高: "+height+ "厘米 "); } public void average_weight(){ this.weight = 67.0; system.out.println( "北京人的平均体重: "+weight+ "公斤 "); } } //主类 public class people_test { public static void main(string[] args) { china_people cp = new china_people(); american_people ap = new american_people(); beijing_people bp = new beijing_people(); cp.speak_hello(); ap.speak_hello(); bp.speak_hello(); cp.average_height(); ap.average_height(); bp.average_height(); cp.average_weight(); ap.average_weight(); bp.average_weight(); cp.china_gongfu(); ap.american_boxing(); bp.beijin_opera(); } } ========================================================== 为什么多次编译有不同的结果??(多次出现,非偶然) 在csdn搜了一下好像很多人都遇到过结果1的情况,请高手解释一下 结果1(错误) --------------------configuration: <default> -------------------- java.lang.nosuchmethoderror: main exception in thread "main " process completed. 结果2(正确) --------------------configuration: <default> -------------------- 你好,吃饭了吗 how do you do ! 您好 中国人的平均身高:173.0厘米 american average height: 188.0 cm 北京人的平均身高:176.0厘米 中国人的平均体重:67.34公斤 american average weight: 80.23 kg 北京人的平均体重:67.0公斤 坐如钟,站如松,睡如弓 直拳、钩拳 京剧术语 process completed. ============================================================= 如果结果中文出现乱码请先参照下面: jcreator 4中文设置: 菜单:configure --> options --> jdk tools --> compiler,选中 <default> ,然后选edit,parameters里面,最前面添加:-encoding utf-8。 parameters原来的默认值为:-classpath "$[classpath] " -d "$[outputpath] " $[modjavafiles] 修改后为: -encoding utf-8 -classpath "$[classpath] " -d "$[outputpath] " $[modjavafiles] |
|
|
|
|