String s1 = new String("Cathy");
String s2;
s2 = s1; // same spot in memory
if (s1 == s2) // true
...
s2 = new String(s1); // each have their own memory (probably!)
if (s1 == s2) // false, and probably WRONG!
...
if (s1.equals(s2)) // true, and probably what you really want!
...
Point p1 = new Point();
Point p2 = new Point(p1);
if (p1 == p2)
System.out.println("YES 1");
else
System.out.println("NO 1");
if (p1.equals(p2))
System.out.println("YES 2");
else
System.out.println("NO 2");
p1.x = 18;
if (p1.equals(p2))
System.out.println("YES 3");
else
System.out.println("NO 3");
p1 = p2;
if (p1 == p2)
System.out.println("YES 4");
else
System.out.println("NO 4");
if (p1.equals(p2))
System.out.println("YES 5");
else
System.out.println("NO 5");
p1.x = 28;