作业-继承2

创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople

和AmericanPeople类重写父类的三个方法)。

package T092202;

public class People {
    protected double height;
    protected double weight;
    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 speakHello()
    {
        System.out.println("你好!!!");
    }
    public void averageHeight()
    {
        System.out.println("平均身高是:"+height);
    }
    public void averageWeight()
    {
        System.out.println("平均体重是:"+weight);
    }
}




package T092202;

public class ChinaPeople extends People {
    public void speakHello()
    {
        System.out.println("你好,我是中国人!");
    }
    public void averageHeight()
    {
        System.out.println("中国人的平均身高是:"+height);
    }
    public void averageWeight()
    {
        System.out.println("中国人的平均体重是:"+weight);
    }
    public void chinaGongfu()
    {
        System.out.println("我会中国功夫:坐如钟,站如松,睡如弓!");
    }
}



package T092202;

public class AmericanPeople extends People {
    public void speakHello()
    {
        System.out.println("你好,我是美国人!");
    }
    public void averageHeight()
    {
        System.out.println("美国人的平均身高是:"+height);
    }
    public void averageWeight()
    {
        System.out.println("美国人的平均体重是:"+weight);
    }
    public void amercianBoxing()
    {
        System.out.println("我会美式拳击:直拳,上勾拳!");
    }
}



package T092202;

public class Test {
    public static void main(String[] args) {
        ChinaPeople chp=new ChinaPeople();
        chp.height=175;
        chp.weight=140;
        chp.speakHello();
        chp.averageHeight();
        chp.averageWeight();
        chp.chinaGongfu();
        AmericanPeople amp=new AmericanPeople();
        amp.setHeight(185);
        amp.setWeight(170);
        amp.speakHello();
        amp.averageHeight();
        amp.averageWeight();
        amp.amercianBoxing();
    }
}

转载于:https://www.cnblogs.com/wangguoning/p/5901499.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值