我会写代码
代码如下:
public class Simulator{
public static void main(String[] args){
cat c = new cat();
Simulator s = new Simulator();
s.playSound(c);
}
void playSound(Animal animal){
animal.cry();
animal.getAnimalName();
}
}
class Animal{
void cry(){
System.out.println("Animal cry");
}
String getAnimalName(){
return("Animal");
}
}
class cat extends Animal{
void cry(){
System.out.println("Cat cry");
}
String getAnimalName(){
return("Cat");
}
}