Results 1 to 2 of 2
Thread: Questions about Polymorphism
- 01-10-2013, 08:08 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 14
- Rep Power
- 0
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
- 01-10-2013, 11:16 AM #2
Member
- Join Date
- Jan 2013
- Location
- INDIA
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
Polymorphism
By kkelv in forum New To JavaReplies: 0Last Post: 03-29-2012, 09:35 PM -
Compile-time Polymorphism or Run-time Polymorphism ?
By dejulial in forum New To JavaReplies: 1Last Post: 03-06-2012, 07:14 PM -
Polymorphism - do you use it?
By N00Bie in forum New To JavaReplies: 10Last Post: 02-15-2011, 04:42 PM -
Polymorphism Help
By AWPtic in forum New To JavaReplies: 5Last Post: 04-06-2009, 04:13 PM -
what is polymorphism
By Nari in forum New To JavaReplies: 5Last Post: 04-04-2008, 03:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks