2-28
class animal {
int height,weight;
void eat()
{
System.out.println("animal eat");
}
void sleep()
{
System.out.println("animal sleep");
}
void breathe()
{
System.out.println("animal breathe");
}
}
class fish extends animal
{
int height;
void breathe()
{
super.breathe();//特殊变量super,提供了对父类的访问。
//可以使用super访问父类被子类隐藏的变量或者覆盖的方法。
//没一子类构造方法的第一条语句,都是隐含地调用super(),
//如果父类没有这种形式的构造函数,那么在编译的时候就会报错
super.height=40;
System.out.println("fish bubble");
}
}
//通过覆盖父类的方法来实现,在运行时根据传递的对象引用,来调用相应的方法
class integration
{
public static void main(String[] args)
{
//animal an=new animal();
fish fh=new fish();
// an.breath();
fh.height=30;
fh.breathe();
}
}
/**
* @param args
*/
/**public static void main(String[] args) {
// TODO Auto-generated method stub
animal an=new animal();
fish fh=new fish();
an.breath();
fh.height=30;
fh.breath();
}
}*/
//instence
//只能说是 子类是父类 奔驰轿车是汽车
//多态性 : 通过覆盖父类的方法来实现,在运行时候根据传递的对象引用,来调用
//相应的方法