public abstract class Animal {
public abstract void cry();
public abstract String getAnimalName();
}
public class Cat extends Animal{
@Override
public void cry() {
// TODO Auto-generated method stub
System.out.println("喵喵喵喵");
}
@Override
public String getAnimalName() {
// TODO Auto-generated method stub
return "猫";
}
}
public class Simulator {
public void playSound(Animal animal)
{
animal.cry();
animal.getAnimalName();
}
}
public class Dog extends Animal{
@Override
public String getAnimalName() {
// TODO Auto-generated method stub
return "狗";
}
@Override
public void cry() {
// TODO Auto-generated method stub
System.out.println("汪汪汪汪");
}
}
public class Application {
public static void main(String[] args) {
// TODO Auto-generated method stub
Simulator simulator = new Simulator();
simulator.playSound(new Dog());
simulator.playSound(new Cat());
}
}
public abstract class Animal { public abstract void cry(); public abstract String getAnimalName();}public class Cat extends Animal{ @Override public void cry() { // TODO Auto-generated meth