//人类
//所谓继承:子类可以继承父类的属性和方法。
//子类继承的父类的属性和方法,但是子类也可以添加自己的属性和方法。
//子类还可以重写从父类继承过来的方法,叫做方法重写(Override)
//Overload:方法重载
//JAVA不允许多重继承。C++是运行多重继承。
//子类如果有和父类名字相同的属性,则会出现覆盖现象。
//1.如果构造方法里有赋初值,则使用赋的值。
//2.如果构造方法里面没赋初值,则使用默认值。
//子类没有出现和父类名字相同的属性,则就是使用父类属性的值。
public class Human extends Animal{
private String name; //姓名
private String nation; //国籍
//int age;
Human()
{
System.out.println("一个人从世界上诞生了...");
}
Human(int age)
{
super(age);
//this.age = age;
System.out.println("一个人从世界上诞生了...");
}
public Human(String name, String nation) {
super();
this.name = name;
this.nation = nation;
}
Human(String name,String nation,int age)
{
//super();
this(age);
this.name= name;
this.nation = nation;
}
@Override
public void eat() {
// TODO Auto-generated method stub
System.out.println(this.name+"正在吃....");
}
@Override
public void sleep() {
// TODO Auto-generated method stub
System.out.println(this.name+"正躺在床上舒服的睡觉zzz....");
}
@Override
public void introduce() {
// TODO Auto-generated method stub
System.out.println("姓名:"+this.name+",国籍:"+this.nation+"年龄:"+this.age+",身高:"+this.height+",体重:"+this.weight);
System.out.println("父类的年龄:"+super.age);
}
//添加新的成员方法
public void thinking()
{
System.out.println(this.name+"正在思考....");
}
}