多态的使用
package ____;
public class TestPolym{
public static void main(String[]args){
animal a=new animal();
animalcry(a);
dog d=new dog();
animalcry(d);
}
static void animalcry(animal a){
a.shout();
}
}
class animal{
public void shout(){
System.out.println("叫了一声");
}
}
class dog extends animal{
public void shout(){
System.out.println("汪汪汪");
}
}
class cat extends animal{
public void shout(){
System.out.println("喵喵喵");
}
}