public class P {
private 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;
}
}
// ...
P a = new P(3);
P b = new P(4);
System.out.println(a.equals(b));What is printed?
- Acheck_circle
false
- B
true
- C
3
- D
4
Explanation
The x values 3 and 4 differ, so equals returns false.