about enumeration interface


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: about enumeration interface

  1. #1
    archana Guest

    about enumeration interface


    hi
    i have one doubt

    Enumeration enum;
    Vector v=new Vector();
    v.addElements("first");
    --
    --

    enum=v.elements()

    //then we directly use

    while(enum.hasMoreElements())
    {
    System.out.println(enum.nextElement())
    }


    Enumeration is an interface so hasMoreElements() and nextElement() are abstract
    methods
    we don't give explicit defination to these methods then also how we can use
    it?

    please guide
    thanks
    archana

  2. #2
    Brent Worden Guest

    Re: about enumeration interface

    Rest assured, elements() returns an object which has a concrete
    implementation of Enumeration. The actual type of the object is unknown to
    you but the type is guaranteed to implement the Enumeration interface. If
    your curious to see what the actual type of object enum is, add
    System.out.println(enum.getClass().getName()) to your code. This should
    convince you that enum's type is a concrete class and most importantly, a
    concrete class that implements Enumeration.

    Brent Worden
    http://www.Brent.Worden.org/


    "archana" <aoke@forindia.com> wrote in message
    news:3a8a30e0$1@news.devx.com...
    >
    > hi
    > i have one doubt
    >
    > Enumeration enum;
    > Vector v=new Vector();
    > v.addElements("first");
    > --
    > --
    >
    > enum=v.elements()
    >
    > //then we directly use
    >
    > while(enum.hasMoreElements())
    > {
    > System.out.println(enum.nextElement())
    > }
    >
    >
    > Enumeration is an interface so hasMoreElements() and nextElement() are

    abstract
    > methods
    > we don't give explicit defination to these methods then also how we can

    use
    > it?
    >
    > please guide
    > thanks
    > archana



  3. #3
    Rajkamal Gopinath Guest

    Re: about enumeration interface


    Hi,

    An Interface can only have abstract methods, but when an Interface points
    to an Object which inturn implements the interface, then the interface reference
    can call the object implementation of the same method.

    1) Enum=v.elements();

    here v.elements() returns an object which implements Enumeration interface
    (i.e) The Object has implementation of hasMoreElements() & nextElement()
    which is referenced by enum


    2) while(enum.hasMoreElements())
    {
    System.out.println(enum.nextElement())
    }

    In the above enum calls the implementation of the object where it is referencing
    and it can only call those methods of object which are defined within itself.


    Reference is different from Object ( which contains data members & methods
    )

    Interface & Abstract Class References can be used to call concrete methods
    when it points to appropriate objects

    Regards

    Rajkamal


    "archana" <aoke@forindia.com> wrote:
    >
    >hi
    >i have one doubt
    >
    >Enumeration enum;
    >Vector v=new Vector();
    >v.addElements("first");
    >--
    >--
    >
    >enum=v.elements()
    >
    >//then we directly use
    >
    >while(enum.hasMoreElements())
    >{
    >System.out.println(enum.nextElement())
    >}
    >
    >
    >Enumeration is an interface so hasMoreElements() and nextElement() are abstract
    >methods
    >we don't give explicit defination to these methods then also how we can

    use
    >it?
    >
    >please guide
    >thanks
    >archana



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center