Forums Register Login

covariant return - easy example .

+Pie Number of slices to send: Send


This code will not give any compilation error in 1.5 . Right ?
Because Second is a subclass of First . And in 1.5 you can override method just by change the return type ( ofcourse it should be compatable with original ) .

Is everything is right ?
Is this is sufficient for covariant return in beta exam ?

thanks a lot .
+Pie Number of slices to send: Send
Yes, the code above is legal in 1.5 as long as the return type of an overriding method is a subclass of the return type of an overridden method.


So what is the output for the above code?

There is an article on covariant parameter types.
+Pie Number of slices to send: Send
I think the output will be :
Second: my()

Logic is same as other overridding methods ...
+Pie Number of slices to send: Send
Thanks a lot Joyce ...
+Pie Number of slices to send: Send
 

I think the output will be :
Second: my()

Logic is same as other overridding methods ...


Correct.
+Pie Number of slices to send: Send
yap second.my coz its overriding..

thanks for this post, i understand it now after a 15 minutes of searching the net!
+Pie Number of slices to send: Send
Thank you for answering this. I am prepping for the SCJP6 and this was touched on in the text
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1612 times.
Similar Threads
Garbage Collection
Is Return Type Included in Method Signature ?
Covariant Question
Question regarding covariant returns
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:53:50.