The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

answer to u

Posted by SPIDY on January 04, 2001 at 11:53 AM

> > Hi Saddy
> > Please send me the program you are talking about. There are things in Java which is not permitted if we , the programmer , do it but in internally they are. For example the two modifiers "abstract" and "final" cannot be used with a class. But when you declare an array of int ( in fact for any array ) like
> > int[] arr = new int[50] ;
> > now when you try to find the class of arr in it is
> > public abstract final [I ...

> > So, you may be right if the program you are referring to has been written by the creator of Java themselves...

> > Thanx
> > Kishori

> Hi Kishori,
> here is the program that i was talking about

>
> class vectors{
> public static void main(String args[])
> {
> Vector a = new Vector();
>
> a.addElement(new String("Hello"));
> a.addElement(new String(" to"));
> a.addElement(new String(" this"));
> a.addElement(new String(" World"));
>
> Enumeration vEnum = a.elements();
> while(vEnum.hasMoreElements())
> {
> System.out.print(vEnum.nextElement());
> }
> }
> }

> Here hasMoreElements() and nextElement() both of Enumeration interface are used without overriding them, how is it working?
> i will be thankful if u could clear my doubt

> saddy


Your doubt is very good ...
Vector object . elements() returns an object of a class which is implementing the interface Enumeration...
i hope u already know that an interface can hold an object reference of its subclass so that happened here ....
but the name of the subclass of that interface Enumeration is not disclosed...so the methods u r calling hasMoreElements() and nextElement() r the methods of that subclass

so that's it u can mail me if u have any doubts...
bye

Spidy...




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us