java人种_Java面向对象练习题继承之人种

bb0bc70589f637d20ed078296164a7e6.png

//People类

package 继承;

public class People {

private String name;

private double height;

private double weight;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

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("Hello");

}

}

//Chinapeople类

package 继承;

//继承

//Object 是所有类的父类

public class Chinapeople extends People {

public void Chinesekongfu()

{

System.out.println("坐如钟,站如松");

}

//重写 也叫覆盖

public void speakHello()

{

System.out.println("你好");

}

}

//Americanpeople类

package 继承;

public class Americanpeople extends People {

public void americanBoxing()

{

System.out.println("直拳,勾拳");

}

}

//Testpeople类

package 继承;

public class Textpeople {

public static void main(String[] args) {

People p=new People();

p.speakHello();

System.out.println("中国人:");

Chinapeople cp=new Chinapeople();

cp.speakHello();

cp.Chinesekongfu();

System.out.println("美国人:");

Americanpeople ap=new Americanpeople();

ap.speakHello();

ap.americanBoxing();

}

}

运行结果

89682603c109ef563cbb447c51a39100.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值