import java.util.*;

class Vecteur {
  private Object[] table;
  private int index = -1;
  Vecteur(int n) {
    table = new Object[n];
  }
  void add(Object element) {
    table[++index] = element;
  }
  Iterateur iterator() {
    return new Iterateur();
  }
    
// Définition par classe nommée interne à une méthode
  Iterator iter() { 
    class Iter implements Iterator {
      int index = -1;
      public boolean hasNext(){
	return index < Vecteur.this.index;
      }
      public Object next() {
	if (index >= Vecteur.this.index)
	  throw new NoSuchElementException();
	return table[++index];
      }
      public void remove() {
	throw new UnsupportedOperationException();
      }
    }
    return new Iter();
  }

// Définition par classe anonyme interne à une méthode
  Iterator iter2() { 
    return new Iterator () {
	int index = -1;
	public boolean hasNext(){
	  return index < Vecteur.this.index;
	}
	public Object next() {
	  if (index >= Vecteur.this.index)
	    throw new NoSuchElementException();
	  return table[++index];
	}
	public void remove() {
	  throw new UnsupportedOperationException();
	}
      };
  }
  // Définition par classe interne nommée
  class Iterateur implements Iterator {
    int indexI = -1;
    public boolean hasNext(){
      return indexI < index;
    }
    public Object next() {
      if (indexI >= index)
	throw new NoSuchElementException();
      return table[++indexI];
    }
    public void remove() {
      throw new UnsupportedOperationException();
    }
  }
}

class VecteurTest {
  public static void main(String[] args) {
    Vecteur v = new Vecteur(10);
    v.add("a"); v.add("b"); v.add("c"); v.add("d");
// 4 itérateurs
    Iterator i = v.iterator();
    Vecteur.Iterateur j = v.iterator();
    Iterator k = v.iter2();
    Iterator h = v.new Iterateur();

    while (i.hasNext()) System.out.print(i.next() + " ");
    System.out.println();

    while (j.hasNext()) System.out.print(j.next() + " ");
    System.out.println();

    v.add("e"); v.add("f");
    while (i.hasNext()) System.out.print(i.next() + " ");
    System.out.println();
  }
}

