package test ;
abstract class Animal
{
abstract void cry();
abstract String getAnimalName();
}
class dogs extends Animal
{ @Override
void cry() {
// TODO Auto-generated method stub
System.out.println("小狗"+" 旺旺 ");
} @Override
String getAnimalName() {
// TODO Auto-generated method stub
return "大黄";
} }
class cats extends Animal
{ @Override
void cry() {
// TODO Auto-generated method stub
System.out.println("小猫"+"喵喵 ");
} @Override
String getAnimalName() {
// TODO Auto-generated method stub
return "小红";
} }
class Simulator
{
void display(Animal myAnimal)
{
myAnimal.cry();
System.out.println(myAnimal.getAnimalName());
}
}
public class hello
{
public static void main(String [] args)
{
//dogs mydog = new dogs();
//cats mycat = new cats();
Simulator mySimulator = new Simulator();
mySimulator.display(new dogs());
mySimulator.display(new cats());
} }