Advertisement
thenewboston

Java Programming Tutorial - 55 - Intoduction to Polymorphism

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