Questions about Polymorphism
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
Re: Questions about Polymorphism
read about benefits of polymorphism. you will get answer........