How does e.hasMoreElements() and e.nextElement() in Enumeration Interface works without definition?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Gunasekaran_Ekambaram
Posted On:   Friday, March 30, 2007 07:03 PM




for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
System.out.println(e.nextElement());

}


In the above code Enumeration interface invokes 2 instance methods


1. e.has MoreElements() 2. e.nextElement()


How does this works by returning a boolean and an object respectively since interfaces doesn't have definitions ?


Thanks in advance !!!

Re: How does e.hasMoreElements() and e.nextElement() in Enumeration Interface works without definition?

Posted By:   Robert_Lybarger  
Posted On:   Saturday, March 31, 2007 09:02 AM

Because "v.elements()" returns a concrete object which implements the Enumeration interface. You are transparently calling those methods on the concrete object, but instead of having to know exactly what the class name of that object, you simply treat it as though it were of interface-type "Enumeration." See also polymorphism.
About | Sitemap | Contact