public class Point {
private int x, y;
public Point(int a, int b) { x = a; y = b; }
// no equals override
}
// Usage:
Point a = new Point(1, 2);
Point b = new Point(1, 2);
System.out.print(a.equals(b));What is printed?
- A
0
- B
true
- C
Compile error
- Dcheck_circle
false
Explanation
Without overriding equals, the inherited Object.equals compares references. a and b are different objects, so equals returns false.