public class Ball { protected int x,y; protected String color; public Ball(String color){ this.color = color; x=0; y=0; } public void move(int dx, int dy){ x+=dx; y+=dy; } public String toString(){ return color + " ball at (" + x + "," + y + ")"; } public boolean equals(Object obj){ if (obj == null) // 1 return false; if (obj == this) // 2 return true; if ( !(obj instanceof Ball) ) // 3 return false; if ( !super.equals(obj) ) // 4 return false; Ball other = (Ball)obj; return // 5 this.x == other.x && this.y == other.y; } public boolean equals2(Object obj){ try{ Ball other = (Ball)obj; return // 5 this.x == other.x && this.y == other.y; }catch(Exception wrong){ return false; } } public static void main(String[] args){ Ball b1; Ball b2 = new Ball("Red"); b2.move(5,10); System.out.println(b2); b1 = b2; b1.move(3,2); System.out.println(b2); b1 = new Ball("Green"); b1.move(2,4); System.out.println(b2); } }