package human;
public class Human
{
//成员属性
private String name;
private int age;
private double height;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
//成员方法
public void speak()
{
System.out.println("你喜欢什么运动呢?");
}
public void yundong()
{
System.out.println("我喜欢打篮球");
}
}
package human;
public class Man extends Human
{
//重写父类的方法
public void speak()
{
System.out.println("我是男生,我叫"+this.getName()+"我的年龄是:"+this.getAge()+"我的身高为:"+this.getHeight());
}
public void yundong()
{
System.out.println("我最喜欢的运动是玩游戏,德玛西亚....");
}
}
package human;
public class Woman extends Human
{
//重写父类方法
public void speak()
{
System.out.println("我是女生,我叫"+this.getName()+"我的年龄是:"+this.getAge()+"我的身高为:"+this.getHeight());
}
public void yundong()
{
System.out.println("我最喜欢的运动是羽毛球");
}
}
package human;
public class Text_human
{
public static void main(String[] args)
{
//实例化man对象
Man m = new Man();
m.setName("张小明");
m.setAge(18);
m.setHeight(178);
m.speak();
m.yundong();
//实例化woman对象
Woman wm = new Woman();
wm.setName("张小红");
wm.setAge(16);
wm.setHeight(160);
wm.speak();
wm.yundong();
//实例化对象
Human h=new Human();
h.speak();
h.yundong();
//定义上转型对象
Human hm=new Man();
hm.setName("tom");
hm.setAge(19);
hm.setHeight(178);
hm.speak();
hm.yundong();
}
}