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

    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();    

    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 "",
    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


  2. #2
    viren2727in is offline Member
    Join Date
    Jan 2013
    Rep Power

    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, 09:35 PM
  2. Compile-time Polymorphism or Run-time Polymorphism ?
    By dejulial in forum New To Java
    Replies: 1
    Last Post: 03-06-2012, 07:14 PM
  3. Polymorphism - do you use it?
    By N00Bie in forum New To Java
    Replies: 10
    Last Post: 02-15-2011, 04:42 PM
  4. Polymorphism Help
    By AWPtic in forum New To Java
    Replies: 5
    Last Post: 04-06-2009, 04:13 PM
  5. what is polymorphism
    By Nari in forum New To Java
    Replies: 5
    Last Post: 04-04-2008, 03: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