interface Animal {
abstract void cry();
abstract void getAnimaName();
}
public class Simulator {
void playSound(Animal animal){
animal.getAnimaName();
animal.cry();
}
}
class Cat implements Animal{
public void cry(){
System.out.println("喵喵喵");
}
public void getAnimaName(){
System.out.print("猫:");
}
}
class Dog implements Animal{
public void cry(){
System.out.print("汪汪汪");
}
public void getAnimaName(){
System.out.print("狗");
}
}
public class Application {
public static void main(String args[]){
Simulator simulator=new Simulator();
simulator.playSound(new Cat());
simulator.playSound(new Dog());
}
}