public class S {
private String x;
public S(String x) { this.x = x; }
public boolean equals(Object o) {
if (!(o instanceof S)) return false;
return ((S) o).x.equals(this.x);
}
}
// ...
S a = new S("hi");
S b = new S("hi");
System.out.println(a.equals(b) + " " + b.equals(a));What is printed?
- Acheck_circle
true true
- B
true false
- C
false true
- D
false false
Explanation
Both objects share the same field value; equals correctly returns true in both directions.