1 package test ; 2 abstract class Animal 3 { 4 abstract void cry(); 5 abstract String getAnimalName(); 6 } 7 class dogs extends Animal 8 { 9 10 @Override 11 void cry() { 12 // TODO Auto-generated method stub 13 System.out.println("小狗"+" 旺旺 "); 14 } 15 16 @Override 17 String getAnimalName() { 18 // TODO Auto-generated method stub 19 return "大黄"; 20 } 21 22 } 23 class cats extends Animal 24 { 25 26 @Override 27 void cry() { 28 // TODO Auto-generated method stub 29 System.out.println("小猫"+"喵喵 "); 30 } 31 32 @Override 33 String getAnimalName() { 34 // TODO Auto-generated method stub 35 return "小红"; 36 } 37 38 } 39 class Simulator 40 { 41 void display(Animal myAnimal) 42 { 43 myAnimal.cry(); 44 System.out.println(myAnimal.getAnimalName()); 45 } 46 } 47 public class hello 48 { 49 public static void main(String [] args) 50 { 51 //dogs mydog = new dogs(); 52 //cats mycat = new cats(); 53 Simulator mySimulator = new Simulator(); 54 mySimulator.display(new dogs()); 55 mySimulator.display(new cats()); 56 } 57 58 }