• 19.创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。



    //People类
    package d922;

    public class People {
    protected double height,weight;
    public void speakHello()
    {
    System.out.println("雷好");
    }
    public double getHeight() {
    return height;
    }
    public void setHeight(double height) {
    this.height = height;
    }
    public double getWeight() {
    return weight;
    }
    public void setWeight(double weight) {
    this.weight = weight;
    }
    public void averageHeight()
    {
    System.out.println(height);
    }
    public void averageweight()
    {
    System.out.println(weight);
    }

    }
    //Chinese 子类
    package d922;

    public class Chinese extends People {
    public void speakHello()
    {
    System.out.println("你好");
    }
    public void averageHeight()
    {
    System.out.println("中国人平均身高"+"180cm");
    }
    public void averageweight()
    {
    System.out.println("中国人平均体重"+"80kg");
    }
    public void chineseKungFu()
    {
    System.out.println("猛龙摆尾");
    }

    }

    //American子类
    package d922;

    public class American extends People {
    public void speakHello()
    {
    System.out.println("Hello");
    }
    public void averageHeight()
    {
    System.out.println("美国人平均身高"+"160cm");
    }
    public void averageweight()
    {
    System.out.println("美国人平均体重"+"60kg");
    }
    public void americanboxing()
    {
    System.out.println("上勾拳");
    }

    }
    //主类
    package d922;

    public class TestA {

    public static void main(String[] args) {
    	  Chinese a = new Chinese( ) ;
            a.setHeight(178);
            a.setWeight(63);
            a.speakHello();
            System.out.println("我是中国人,身高"+a.getHeight()+"cm,体重"+a.getWeight()+"kg");
            a.averageHeight();
            a.averageweight();
            a.chineseKungFu();
            American b = new American( ) ;
            b.setHeight(180);
            b.setWeight(67);
            b.speakHello();
            System.out.println("我是美国人,身高"+b.getHeight()+"cm,体重"+b.getWeight()+"kg");
            b.averageHeight();
            b.averageweight();
            b.americanboxing();
    
    }
    

    }
    //运行结果
    你好
    我是中国人,身高178.0cm,体重63.0kg
    中国人平均身高180cm
    中国人平均体重80kg
    猛龙摆尾
    Hello
    我是美国人,身高180.0cm,体重67.0kg
    美国人平均身高160cm
    美国人平均体重60kg
    上勾拳

  • 相关阅读:
    HDU 1317 XYZZY(floyd+bellman_ford判环)
    UVa 10791 最小公倍数的最小和(唯一分解定理)
    UVa 12169 不爽的裁判
    UVa 11582 巨大的斐波那契数!(幂取模)
    POJ 1142 Smith Numbers(分治法+质因数分解)
    HDU 1595 find the longest of the shortest
    UVa 11090 在环中
    UVa 10917 林中漫步
    UVa 11374 机场快线
    POJ 1503 Integer Inquiry
  • 原文地址:https://www.cnblogs.com/nicebaby/p/5897338.html
Copyright © 2020-2023  润新知