wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method with interface return type 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 "method with interface return type" Watch "method with interface return type" New topic
Author

method with interface return type

diwakar k.
Greenhorn

Joined: Apr 18, 2004
Posts: 10
It is written in K&B that a method can return interface implementer by citing the following snippet:


Myquestion is when interfaces are not part of the object's inhertance tree,how could a return type (here an object of class Gum) be returned?? In otherwords is a return type of implementer be returned??

Edited by Corey McGlone: Added CODE Tags
[ August 02, 2004: Message edited by: Corey McGlone ]
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
diwakar k.,

Welcome to Javaranch

We'd like you to read the Javaranch Naming Policy and change your publicly displayed name (change it here) to comply with our unique rule. Thank you.


SCJP Tipline, etc.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by diwakar k.:
Myquestion is when interfaces are not part of the object's inhertance tree,how could a return type (here an object of class Gum) be returned?? In otherwords is a return type of implementer be returned??


There is no requirement that says that an object to be returned from a method need be in the inheritance tree of the class in which the method is defined. In this case, a new object will be created that implements the interface. That object is then returned. There is no need for that interface to be a part of the inheritance tree of your class - the interface needs only be accessible from this class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method with interface return type