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
上勾拳

posted @ 2016-09-22 17:50  削肾客  阅读(1292)  评论(0编辑  收藏  举报