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