Forums Register Login

Polymorphic method declarations

+Pie Number of slices to send: Send
 

A reference variable can refer to any object of the same type as the declared reference, or it can refer to any subtype of the declared type!



I have seen this in K & B SCJP Book. What is the main advantage in this kind of method declarations ?


What is the problem with this declaration ?


When should we choose polymorphic method declarations?
+Pie Number of slices to send: Send
In those cases where you want type specific methods to be executed. Like Animal class having an eat method. Now based on cat and dog subclasses object, you prefer to have the eat method of either dog/cat executed.

Example:


[ February 08, 2008: Message edited by: Gitesh Ramchandani ]
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 671 times.
Similar Threads
Generics Question
Generic Object Types vs Generic References
***Confusing Generic question ****
Difference Between These 2 Declarations.
Polymorphic Declaration
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:11:42.