next up previous contents
Next: Inner and Nested Classes: Up: Java Notes Previous: Inner and Nested Classes:

Inner and Nested Classes: Anonymous 4

/**
  * From Java Tutorial Second Edition 1998
  * David Flanagan, O'Reilly
  */
public class Stack {
  private Vector items;

    ... //code for Stack's methods and 
        //constructors not shown...

  public Enumeration enumerator() {
    return new Enumeration() {
      int currentItem = items.size() - 1;
       public boolean hasMoreElements() {
         return (currentItem >= 0);
       }
       public Object nextElement() {
         if (!hasMoreElements())
           throw new NoSuchElementException();
         else
           return items.elementAt(currentItem--);
      }
    }
  }
}



Ananda Amatya
9/15/1999