Advertisement
thenewboston

Java Programming Tutorial - 56 - Polymorphic Arguments

Aug 22nd, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class apples {
  2.    public static void main(String[] args){
  3.      
  4.       fatty bucky = new fatty();
  5.       food fo = new food();
  6.       food po = new potpie();
  7.      
  8.       bucky.digest(fo);
  9.       bucky.digest(po);
  10.    }
  11. }
  12.  
  13.  
  14. public class potpie extends food {
  15.    void eat(){
  16.       System.out.println("this potpie is great");
  17.    }
  18.  
  19. }
  20.  
  21.  
  22. public class tuna extends food{
  23.    void eat(){
  24.       System.out.println("this tuna is great");
  25.    }
  26. }
  27.  
  28. public class food {
  29.    
  30.    void eat(){
  31.       System.out.println("this food is great");
  32.    }
  33.  
  34. }
  35.  
  36. public class fatty {
  37.    
  38.    public void digest(food x){
  39.       x.eat();
  40.    }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement