This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface Question" Watch "Interface Question" New topic
Author

Interface Question

Pat Moran
Greenhorn

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.


pm
David Peterson
author
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
hth
 
GeeCON Prague 2014
 
subject: Interface Question