1 abstract class Animal 2 { 3 abstract void eat(); 4 } 5 6 class Cat extends Animal 7 { 8 void eat() 9 { 10 System.out.println("eat fish"); 11 } 12 } 13 14 class Dog extends Animal 15 { 16 void eat() 17 { 18 System.out.println("gnaw bone"); 19 } 20 } 21 22 class Pig extends Animal 23 { 24 void eat() 25 { 26 System.out.println("eat rice"); 27 } 28 } 29 30 class Duotai 31 { 32 public static void main(String[] args) 33 { 34 method(new Cat()); 35 method(new Dog()); 36 method(new Pig()); 37 } 38 public static void method(Animal a) 39 { 40 a.eat(); 41 } 42 }