interface

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manohar753
    New Member
    • Jul 2008
    • 2

    #1

    interface

    as my knowledge every method that is writen in interface should be implemented.
    but Iterator&Listit erator are two interfaces.but these have some methods like hasnext().these methods are directly calll using reference without writing code.
    so some body plz clarify my doubts.plese dont hesitate if it is basic
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    With interface types (class types, too) you use them as well as define classes that implement (subclass) them:
    Code:
    List list = ...
    Iterator it = list.iterator();
    while (it.hasNext()) {
        Object obj = it.next();
        ...
    }
    Here I am using an Iterator, not writing a class that implements Iterator. Here is the same code, with the names changed:
    Code:
    A a= ...
    B b = a.f();
    while (b.g()) {
        C c= b.h();
        ...
    }
    Does your understanding of this code change if I inform you "A is a class type" versus "A is an interface type"? "B is a class type" versus "B is an interface type"? It shouldn't, should it?

    Comment

    Working...