我们都知道哺乳动物有很多叫声。
比方说:舔狗的汪汪,猫星人的“冷冷喵”,漂亮妹妹的“好好看”,吃货妹妹的“好好次”……
这些都是哺乳动物的多态,父类的某个方法被重写了,可以有自己的功能行为,这些各自不同的表现就是变态,口误,是多态。
class Animal{
void cry(){
}
}
class puppy extends Animal{
void cry(){
System.out.println("wang_wang");
}
}
class cat extends Animal{
void cry(){
System.out.println("miao_miao");
}
}
public class Example5_9 {
public static void main(String args[]){
Animal animal;;
animal = new pubby();
animal.cry();//小狗叫叫
animal = new cat();
animal.cry();//高冷星人叫
}
}