Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package polymophism;
  2.  
  3. public class Human {
  4.  
  5.     public void eat() {
  6.         System.out.println("Human eat");
  7.     }
  8.  
  9. }
  10.  
  11. public class Woman extends Human {
  12.     public void eat() {
  13.         System.out.println("Woman eat");
  14.     }
  15. }
  16.  
  17. public class Man extends Human {
  18.     public void eat() {
  19.         System.out.println("Man eat");
  20.     }
  21. }
  22.  
  23. public class Tester {
  24.  
  25.     public static void main(String[] args) {
  26.         Woman w = new Woman();
  27.         Man m = new Man();
  28.         Human hm = new Man();
  29.         Tester tester = new Tester();
  30.         tester.eat(m);
  31.         tester.eat(hm);
  32.         tester.eat(w);
  33.     }
  34.  
  35.     private void eat(Human h) {
  36.         h.eat();
  37.     }
  38.  
  39. }