中国人与美国人(继承与接口)

中国人与美国人(继承与接口),第1张

People.java

public class People {

protected double weight,height;

public void speakHello(){

    System.out.println("yayayaya");

}

public void averageHeight(){

    height=173;

    System.out.println("average height:"+height);

}

public void averageWeight(){

    weight=70;

    System.out.println("average weight:"+weight);

}

}

ChinaPeople.java

public class ChinaPeople extends People{

    public void speakHello(){

        System.out.println("您好");

}

    public void averageHeight(){

        height=168.78;

        System.out.println("中国人的平均身高:"+height+"厘米");

    }

    public void averageWeight(){

        System.out.println("中国人的平均体重:65公斤");

    }

    public void chinaGongfu(){

        System.out.println("坐如钟,站如松,睡如弓");

    }

}

AmericanPeople.java

public class AmericanPeople extends  People{

    public void speakHello(){

        System.out.println("How do you do");

    }

    public void averageHeight(){

        System.out.println("American's average height:176cm");

}

    public void averageWeight(){

        weight=75;

        System.out.println("American's average weight:"+weight+"kg");

    }

    public void americanBoxing(){

        System.out.println("直拳、勾拳、组合拳");

    }

    }

BeijingPeople.java

public class BeijingPeople extends ChinaPeople{

    public void averageHeight(){

        System.out.println("北京人的平均身高:172.5厘米");

    }

    public void averageWeight(){

       

        System.out.println("北京人的平均体重:70公斤");

    }

    public void beijingOpera(){

        System.out.println("花脸、青衣、花旦和老生");

    }

}

Example.java

public class Example {

    public static void main(String[] args) {

ChinaPeople chinaPeople=new ChinaPeople();

AmericanPeople americanPeople=new AmericanPeople();

BeijingPeople beijingPeople=new BeijingPeople();

chinaPeople.speakHello();

beijingPeople.speakHello();

chinaPeople.averageHeight();

americanPeople.averageHeight();

beijingPeople.averageHeight();

chinaPeople.averageWeight();

americanPeople.averageWeight();

beijingPeople.averageWeight();

chinaPeople.chinaGongfu();

americanPeople.americanBoxing();

beijingPeople.beijingOpera();

beijingPeople.chinaGongfu();

    }

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/798327.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存