import java.util.*;

class cat {}
class dog {}

class RestrictedVector extends Vector {
  private Class vtype;
  public void add(Object o) throws Exception {
    if(vtype == null)
      vtype = o.getClass();
    if(o.getClass() != vtype)
      throw new Exception("Incompatible type in RestrictedVector");
    addElement(o);
  }
}

public class ch11ex3 {
  public static void main(String args[]) throws Exception {
    RestrictedVector rv = new RestrictedVector();
    rv.add(new cat());
    rv.add(new dog());
  }
}
