public class P {
int x;
public P(int x) { this.x = x; }
public boolean equals(Object o) {
if (!(o instanceof P)) return false;
return ((P) o).x == this.x;
}
}
System.out.println(new P(3).equals(new P(3)));What is printed?
- A
false
- B
ClassCastException
- Ccheck_circle
true
- D
Compile-time error
Explanation
The override compares the x fields, which are equal.