Results 1 to 2 of 2
  1. #1
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    18
    Rep Power
    0

    Default Questions about Polymorphism

    Java Code:
    public class food{
      void eat(){
        System.out.println("this food is great");
      }
    
    }
    
    public class tuna extends food{
      void eat(){
        System.out.println("tuna is great");
      }
    
    }
    
    *********************************************
    
    public class apple{
      public static void main(String[] args){
          
        food fo = new food();    
        food ft = new tuna();    
        
        fo.eat();
        ft.eat();
        
        }
    }


    According to the following code:
    tuna ta = new tuna();
    food ft = new tuna();

    1) what is the difference between the object "ta" and "ft"?
    2) what is the pros?
    3) when using the code "tuna ta = new tuna();" and execute "ta.eat()",
    it also produce the same result of "food ft = new tuna();",
    then why "food ft = new tuna();" is introduced by Polymorphism?

    I am a bit confuse on invoking the Polymorphism.
    Hope anyone can help

    Thanks

  2. #2
    viren2727in is offline Member
    Join Date
    Jan 2013
    Location
    INDIA
    Posts
    18
    Rep Power
    0

    Default Re: Questions about Polymorphism

    read about benefits of polymorphism. you will get answer........

Similar Threads

  1. Polymorphism
    By kkelv in forum New To Java
    Replies: 0
    Last Post: 03-29-2012, 10:35 PM
  2. Compile-time Polymorphism or Run-time Polymorphism ?
    By dejulial in forum New To Java
    Replies: 1
    Last Post: 03-06-2012, 08:14 PM
  3. Polymorphism - do you use it?
    By N00Bie in forum New To Java
    Replies: 10
    Last Post: 02-15-2011, 05:42 PM
  4. Polymorphism Help
    By AWPtic in forum New To Java
    Replies: 5
    Last Post: 04-06-2009, 05:13 PM
  5. what is polymorphism
    By Nari in forum New To Java
    Replies: 5
    Last Post: 04-04-2008, 04:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •