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
posted
0
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.
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.