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

package People;

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()
    {
        
    }
    public void averangeHeight()
    {
        
    }
    public void averangeWeight()
    {
        
    }
    
}
package People;

public class ChinesePeople extends People
{
     public void speakHello()
        {
            System.out.println("你好,我来自中国,我的身高是:"+this.height+"我的体重是:"+this.weight);
        }
        public void averangeHeight()
        {
            System.out.println("我们中国人的平均身高是1.70米");
        }
        public void averangeWeight()
        {
            System.out.println("我们中国人的平均体重是55kg米");
        }
        public void chineseKongfu()
        {
            System.out.println("我会中国功夫--太极拳,借力用力,以慢打快。");
        }
}
package People;

public class AmericanPeople extends People
{
    public void speakHello()
    {
        System.out.println("你好,我来自美国,我的身高是:"+this.height+"我的体重是:"+this.weight);
    }
    public void averangeHeight()
    {
        System.out.println("我们美国人的平均身高是1.72米");
    }
    public void averangeWeight()
    {
        System.out.println("我们美国人人的平均体重是75kg米");
    }
    public void icanBoxing()
    {
        System.out.println("我会拳击,左勾拳,右勾拳,哈哈哈");
    }
}
package People;

public class TEXT_people 
{

    public static void main(String[] args)
    {
        ChinesePeople cp=new ChinesePeople();
        cp.setHeight(168);
        cp.setWeight(65);
        cp.speakHello();
        cp.averangeHeight();
        cp.averangeWeight();
        cp.chineseKongfu();
        
        AmericanPeople ap=new AmericanPeople();
        ap.setHeight(155);
        ap.setWeight(55);
        ap.speakHello();
        ap.averangeHeight();
        ap.averangeWeight();
        ap.icanBoxing();
    }
    
    

}

 

posted @ 2016-09-22 16:05  HRZJ  阅读(1716)  评论(0编辑  收藏  举报