(一)Example.java
classPeople
{
protecteddoubleweight,height;
publicvoidspeakHello( )
{
System.out.println("yayawawa");
}
publicvoidaverageHeight()
{
height=173;
System.out.println("average height:"+height);
}
publicvoidaverageWeight( )
{
weight=70;
System.out.println("average weight:"+weight);
}
}
classChinaPeopleextendsPeople
{
publicvoidspeakHello( ){
System.out.println("你好,吃了吗");
}// 重写public void speakHello( )方法,要求输出类似“你好,吃了吗”
// 这样的汉语信息
publicvoidaverageHeight( ){
System.out.println("中国人的平均身高:168.78厘米");
}// 重写public void averageHeight( )方法,要求输出类似
// “中国人的平均身高:168.78厘米”这样的汉语信息
publicvoidaverageWeight( ){
System.out.println("中国人的平均体重:65公斤");
}// 重写public void averageWeight( )方法,
// 要求输出类似“中国人的平均体重:65公斤”这样的汉语信息
publicvoidchinaGongfu ()
{
System.out.println("坐如钟,站如松,睡如弓");// 输出中国武术的信息,如"坐如钟,站如松,睡如弓"等
}
}
classAmericanPeopleextendsPeople
{
publicvoidspeakHello(){
System.out.println("How do you do");
}//重写public void speakHello()方法,要求输出类似“How do you do”这样的英语信息
publicvoidaverageHeight( ){
System.out.println("average height:"+height);
}// 重写public void averageHeight( )方法
publicvoidaverageWeight( ){
System.out.println("average weight:"+weight);
}// 重写public void averageWeight( )方法
publicvoidamericanBoxing()
{
System.out.println("直拳"+"钩拳");// 输出拳击的信息,如“直拳”、“钩拳”等
}
}
classBeijingPeopleextendsChinaPeople
{
publicvoidspeakHello( ){
System.out.println("您好");
}// 重写public void speakHello( )方法,要求输出类似“您好”这样的汉语信息
publicvoidaverageHeight( ){
System.out.println("average weight:"+weight);
}// 重写public void averageHeight( )方法
publicvoidaverageWeight( ){
System.out.println("average weight:"+weight);
}// 重写public void averageWeight( )方法
publicvoidbeijingOpera()
{
System.out.println("唱脸谱");// 输出京剧的信息
}
}
publicclassExample
{
publicstaticvoidmain(String args[ ])
{
ChinaPeople chinaPeople=newChinaPeople( );
AmericanPeople americanPeople=newAmericanPeople( );
BeijingPeople beijingPeople=newBeijingPeople( );
chinaPeople.speakHello( );
americanPeople.speakHello( );
beijingPeople.speakHello( );
chinaPeople.averageHeight( );
americanPeople.averageHeight( );
beijingPeople.averageHeight( );
chinaPeople.averageWeight( );
americanPeople.averageWeight( );
beijingPeople.averageWeight( );
chinaPeople.chinaGongfu( );
americanPeople.americanBoxing( );
beijingPeople.beijingOpera( ) ;
beijingPeople.chinaGongfu( );
}
}
运行结果: