abstract class Animal//抽象类
{
abstract void Cry();//抽象方法2个
abstract void getAnimalName();
}
public class Simulator
{
void playSound(Animal animal)
{
animal.getAnimalName();
animal.Cry();
}
}
public class Dog extends Animal
{
void Cry()
{
System.out.println("voice:WANG!WANG!WANG!");
}
void getAnimalName()
{
System.out.printf("Dog's");
}
}
public class Cat extends Animal
{
void Cry()
{
System.out.println("voice:miao!miao!miao!");
}
void getAnimalName()
{
System.out.printf("Cat's");
}
}
public class APPlication
{
public static void main(String args[])
{
Simulator simulator=new Simulator();
simulator.playSound(new Cat());
simulator.playSound(new Dog());
}
}