//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]

解决方案 »

  1.   

    请教高手:这真是Jcreator4的问题吗??如何解决?
      

  2.   

    好久没有用过jcreator了lz是不是有时候没有运行people_test这个类,如果运行的是people或者其他的话就会出现结果1的异常
    还有类名应该大写,养成良好的编码习惯会减少很多不必要的麻烦~
      

  3.   

    people_test是主类哦,怎么会没运行??类名大写是好的习惯吗,也请高手发表一下意见。
      

  4.   

    不好意思,是类名首字母应该大写,还有方法名首单词小写,第二个单词开始要大写首字母随便一本java教材应该都有提及到
    你建立的是不是一个project?如果是project的话点击execute project应该不会出错的,如果不是project的话所execute的file必须是people_test,如果你是在people下点击execute file的话就会出现找不到main方法的error~