public class Point {
int x, y;
public Point(int x, int y) { this.x = x; this.y = y; }
}
Point p1 = new Point(1, 2);
Point p2 = new Point(1, 2);
System.out.println(p1.equals(p2));What is printed?
- A
NullPointerException
- B
Compile-time error
- C
true
- Dcheck_circle
false
Explanation
Without overriding <code>equals</code>, the inherited Object.equals does reference comparison. p1 and p2 are distinct objects.