/* * file: Point.java * Illustrates references and cloning. * * @author Chee Yap * Honors Basic Algorithms, Fall 2000 */ class Point implements Cloneable // if this is missing, get runtime error { public int x, y; Point() { x = 0; y = 0; }//Point() Point(int a, int b){ x = a; y = b; }//Point(a,b) public static void main (String[] args) throws Exception { int x = 1; int y = x; // value is copied x = 2; if (y == x) System.out.println("ERROR!"); else System.out.println("RIGHT!"); Point p = new Point(0,0); Point q = p; // only reference is copied! p.x = 1; if (p == q) System.out.println("RIGHT!"); else System.out.println("ERROR!"); Point r = (Point)p.clone(); if (p == r) System.out.println("ERROR!"); else System.out.println("RIGHT!"); } //main method } //Point Class