public class MyApplication2 {
public static void main(String[] args) {
People p1 = new People(0,0);
ChinaPeople p2 =new ChinaPeople(0,0,"yellow");
}
}
class People{
double weight;
double height;
public People(double weight, double height) {
this.weight = weight;
this.height = height;
speakHello();
averageHeight();
averageWeight();
}
public void speakHello(){
System.out.println("我是人");
}
public void averageHeight(){
this.height = 170;
System.out.println("我的平均身高是:" + height);
}
public void averageWeight(){
this.weight = 70;
System.out.println("我的平均体重是:" + weight);
}
}
class ChinaPeople extends People{
private String skin;
public ChinaPeople(double weight, double height , String skin) {
super(weight, height);
this.skin = skin;
getSkin();
}
public void speakHello(){
System.out.println("我是中国人");
}
public void averageHeight(){
this.height = 175;
System.out.println("我的平均身高是:" + height);
}
public void averageWeight(){
this.weight = 65;
System.out.println("我的平均体重是:" + weight);
}
public void getSkin() {
System.out.println("中国人的肤色是:" + skin);
}
2021-05-09
最新推荐文章于 2022-03-11 15:51:27 发布