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 Types 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 Types" Watch "Covariant Return Types" New topic
Author

Covariant Return Types

Jerry Ragland
Ranch Hand

Joined: Apr 26, 2005
Posts: 33
class Programmer {
Programmer debug() {return this;}
}

class SCJP extends Programmer {
Object debug() {return this;}
}

why the compilation fails saying in compatible return type during an override?
All class extends Object so SCJP IS-A Object and hence return this; should be accepted as a covariant return type ... Correct???

Some one please explain....

Thanks,
Jerry Ragland.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Object is a supertype of Programmer and not a subtype

Covariant Return types only applies to the subtypes of the overriding return type. In this case Programmer and al subclasses of Programmer.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Jerry Ragland
Ranch Hand

Joined: Apr 26, 2005
Posts: 33
Thanks for the clarification.. Got it...

-Jerry.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Covariant Return Types
 
Similar Threads
OO Ques
Lets add some good scjp 5 questions here
Programmer debug() what does it mean? return type?
SCJP 5.0 K&B Book,pg 162 Qn.10
Inheritance seems simple