File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Interface Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface Question" Watch "Interface Question" New topic

Interface Question

Pat Moran

Joined: Feb 11, 2004
Posts: 20
It seems like we can create and use Enumerators and Iterators "on the fly" without specifically listing those interfaces in an "implements" clause, but we do have to specifically list things like Serializable in an "implements" clause. What is the difference in the use of interfaces that sometimes requires their specific listing in an "implements" clause?
Thanks in advance for any insights.

David Peterson
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
The difference is whether your class implements something or just uses it.
Your class uses Enumerators and Iterators, but does not implement them.
Hope this makes it clearer.
David Peterson
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Adding a tad more to what David has already said : Your class uses Enumeration by including the java.util package via the import statement.

Ever Existing, Ever Conscious, Ever-new Bliss
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
my 2�
This is a good example of is-a and has-a relationships.
If your class 'is-a' Iterator, you need to implement Iterator and provide definitions for the interface's methods
If your class 'has-a' Iterator, you need to import the java.util package (or java.util.Iterator itself) to use the instance of the Iterator
I agree. Here's the link:
subject: Interface Question
It's not a secret anymore!