File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes covariant return - easy example . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "covariant return - easy example ." Watch "covariant return - easy example ." New topic
Author

covariant return - easy example .

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830


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 .
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
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.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I think the output will be :
Second: my()

Logic is same as other overridding methods ...
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Thanks a lot Joyce ...
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
I think the output will be :
Second: my()

Logic is same as other overridding methods ...

Correct.
Christian Joseph
Ranch Hand

Joined: Jan 07, 2011
Posts: 43
yap second.my coz its overriding..

thanks for this post, i understand it now after a 15 minutes of searching the net!
Bryan Cutkelvin
Greenhorn

Joined: Oct 17, 2013
Posts: 1
Thank you for answering this. I am prepping for the SCJP6 and this was touched on in the text
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: covariant return - easy example .
 
Similar Threads
Garbage Collection
Covariant Question
Question regarding covariant returns
Is Return Type Included in Method Signature ?