package java02;
//类的某个方法被其子类重写时,可以各自产生自己的功能行为;
//当把子类创建的对象引用赋给一个父类对象时(向上转型),
//这个向上转型对象在调用这个实例方法时,就可能具有多种形态。
class Animal {
void cry() {
}
}
class Dog extends Animal {
void cry() {
System.out.println(“旺旺旺”);
}
}
class Cat extends Animal {
void cry() {
System.out.println(“喵喵喵”);
}
}
public class 类的继承多态 {
public static void main(String args[]) {
Animal animal;
animal = new Dog();
animal.cry();
animal = new Cat();
animal.cry();
}
}