//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Example 3.6 on page 58
//  Incorrect cloning

class Widget implements Cloneable
{ int n;
  Widget w;
  Widget(int n) { this.n = n; }

  public Object clone() throws CloneNotSupportedException
  { return super.clone();
  }

  public String toString()
  { return "(" + n + "," + w.n + ")";
  }
}

public class Ex0306
{ public static void main(String[] args)
        throws CloneNotSupportedException
  { Widget x = new Widget(44);
    x.w = new Widget(66);
    System.out.println("x = " + x);
    Widget y = (Widget)x.clone();
    System.out.println("y = " + y);
    x.n = 55;
    x.w.n = 77;
    System.out.println("x = " + x);
    System.out.println("y = " + y);
  }
}
