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 Enumeration 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 "Enumeration" Watch "Enumeration" New topic
Author

Enumeration

Jennifer Warren
Ranch Hand

Joined: Aug 24, 2001
Posts: 53
Please some body tell me where are the methods of enumeration interface are defined/ implemented. As we can do as follows.
Vector v = new Vector();
// code which add obj's to vector v.
Enumeration vEnum = v.element();
// use methods of Enumeration interface to read obj's in the //vector v.
thanks in advance
Jennifer.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
defined in java.util.Enumeration
you have two methods to iterate over the enumeration
public boolean hasMoreElements()
Tests if this enumeration contains more elements.

public Object nextElement()
Returns the next element of this enumeration if this enumeration object has at least one more element to provide
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Jennifer Warren
Ranch Hand

Joined: Aug 24, 2001
Posts: 53
Enumeration is an interface and my understanding is that you can not define the methods in interface they have to implemented in some class. I did try to do that on my own by defining my own interface and adding a method with code it gives a compilation error. I hope you understand what i'm saying.
Thanx.
Jennifer.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
I undertsand what you are saying very well, but let's peek at the elements() method in the Vector class

As you can see, the Vector class provides its own implementation of the Enumeration interface by means of the declaration of an anonymous inner class which implements the methods of the Enumeration interface. So the return type is Enumeration (an interface type) but the actual object being returned is an anonymous implementation of the Enumration interface which is why you can access the methods of Enumeration without even knowing how it is implemented, this is the power of interfaces !
HIH

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
Jennifer Warren
Ranch Hand

Joined: Aug 24, 2001
Posts: 53
that what i expected it to be but could not find the code for the element method in the vector class. Still you've been a great help and now i can sleep.
Thanx.
Jennifer.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Sweet (Java) Dreams

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enumeration
 
Similar Threads
Question on Enumeration Interface
castNotSupportedException
Implementation of Interfaces
Enumeration and Vector
[Interview Q] Why does array index begin with 0 instead of 1 ???