| Author |
return type of method
|
Janki Shah
Ranch Hand
Joined: Nov 23, 2011
Posts: 136
|
|
According to k&b covariant type is possible. But this class does not have a Has-A or Is-A relationship.
|
 |
gurpeet singh
Ranch Hand
Joined: Apr 04, 2012
Posts: 868
|
|
|
there is no obligation on the return type of the method as long as it follow java syntax rules and compiles. why are you saying that the method cannot return variable of the type Main. the co-variant type is for overridding methods. Overriding is related to inheritance. when a method overriddes another method then the overridding method can have co-variant return type ,which means its return type can be any sub-class of the return type of overridden method. there is nothing stopping you from returning object of another class from your methods.
|
OCPJP 6(100 %) OCEWCD 6(91 %)
|
 |
Janki Shah
Ranch Hand
Joined: Nov 23, 2011
Posts: 136
|
|
|
Thank you Gurpeet for clearing my doubt.
|
 |
 |
|
|
subject: return type of method
|
|
|