• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface Question

 
Pat Moran
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 382
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding a tad more to what David has already said : Your class uses Enumeration by including the java.util package via the import statement.
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic