People父类:
public class People {
float height = 0.0f;
int weight = 0;
People()
{
this.height = height;
this.weight = weight;
}
public void speakHello()
{
System.out.println("你好");
}
public void averageWeight()
{
}
public void averageHeight()
{
}
ChinaPeople 子类:
public class ChinaPeople extends People {
ChinaPeople()
{
this.height = height;
this.weight = weight;
}
public void chinaMartial()
{
System.out.println("中国是崇尚和平的,人不犯我我不犯人,人若犯我,嘿嘿~~");
}
public void averageWeight()
{
weight = 110;
System.out.println("中国人平均体重是 "+weight);
}
public void averageHeight()
{
height = 1.75f;
System.out.println("中国人平均身高是 "+height);
}
public void speakHello()
{
System.out.println("中国你好");
}
}
AmaricanPeople子类:
public class AmericanPeople extends People {
AmericanPeople()
{
this.height = height;
this.weight = weight;
}
public void AmericanBoxing()
{
System.out.println("美国的拳击超棒 , 看看WWE你就知道到底有多帅了");
}
public void averageWeight()
{
weight = 120;
System.out.println("美国人平均体重是 "+weight);
}
public void averageHeight()
{
height = 1.80f;
System.out.println("美国人平均身高是 "+height);
}
public void speakHello()
{
System.out.println("美国你好");
}
}
BeijingPeople 子类:
public class BeijingPeople extends ChinaPeople {
BeijingPeople()
{
this.height = height;
this.weight = weight;
}
public void BeijingOpera()
{
System.out.println("京剧源远流长 , so cool");
}
public void averageWeight()
{
weight = 110;
System.out.println("北京人平均体重是 "+weight);
}
public void averageHeight()
{
height = 1.75f;
System.out.println("北京人平均身高是 "+height);
}
public void speakHello()
{
System.out.println("北京人你好");
}
}
Test 测试类:
public class Test {
public static void main(String args[])
{
People p = new People();
p.speakHello();
ChinaPeople c = new ChinaPeople();
c.speakHello();
c.chinaMartial();
c.averageHeight();
c.averageWeight();
AmericanPeople a = new AmericanPeople();
a.speakHello();
a.AmericanBoxing();
a.averageHeight();
a.averageWeight();
BeijingPeople b = new BeijingPeople ();
b.speakHello();
b.BeijingOpera();
b.averageHeight();
b.averageWeight();
}
}
运行结果:
你好
中国你好
中国是崇尚和平的,人不犯我我不犯人,人若犯我,嘿嘿~~
中国人平均身高是 1.75
中国人平均体重是 110
美国你好
美国的拳击超棒 , 看看WWE你就知道到底有多帅了
美国人平均身高是 1.8
美国人平均体重是 120
北京人你好
京剧源远流长 , so cool
北京人平均身高是 1.75
北京人平均体重是 110