/*编写一个java应用程序,程序中有四个类:People,ChinaPeople,AmericanPeople,BeijingPeople,people类有访问权限是protected的double类型的weight和height以及public void speakHello();public void averageHeight(),public void averageWeight()方法。Chinapeople类是people的子类,新增public void gongfu()方法,以及重写public void speakHello();public void averageHeight(),public void averageWeight()方法。Americanpeople类是people的子类,新增 public void americanBoxing(),以及重写public void speakHello();public void averageHeight(),public void averageWeight()方法。BeijingPeople类是Chinapeople的子类,新增 public void Opera(),以及重写public void speakHello();public void averageHeight(),public void gongfu()方法,public void averageWeight()方法。*/ class People{ protected double height; protected double weight; public void speakHello(){ System.out.println("hello"); } public void averageHeight(){} public void averageWeight(){} } class AmericanPeople extends People{ public void speakHello(){ System.out.println("american i"); } public void averageHeight(){} public void averageWeight(){} public void americanBoxing(){} } class ChinaPeople extends People{ public void speakHello(){ System.out.println("china hi"); } public void averageHeight(){} public void averageWeight(){} public void chinaGongfu(){} } class BeijingPeople extends ChinaPeople{ public void speakHello(){ System.out.println("BEIJING HI"); } public void averageHeight(){} public void averageWeight(){} public void chinaGongfu(){} public void beijingOpera(){} } public class Alei { public static void main(String []args){ //创建 子类AmericanPeople的一个实例对象,使用默认构造法 AmericanPeople a=new AmericanPeople(); //方法重写 a.speakHello(); a.averageHeight(); a.averageWeight(); //创建子类ChinaPeople的一个实例对象,使用默认构造法 ChinaPeople b=new ChinaPeople(); //方法重写 b.speakHello(); b.averageHeight(); b.averageWeight(); //创建子类BeijingPeople的实例对象,使用默认构造法 BeijingPeople c=new BeijingPeople(); //方法重写 c.speakHello(); c.averageHeight(); c.averageWeight(); c.chinaGongfu();}}
运行结果如下:
american ichina hiBEIJING HI