public class Tag {
private String label;
public Tag(String l) { label = l; }
}
// ...
Tag t1 = new Tag("X");
Tag t2 = new Tag("X");
System.out.println(t1.equals(t2));What is printed?
- Acheck_circle
false
- B
true
- C
X
- D
Compile-time error
Explanation
Without overriding equals, Object's equals compares references; t1 and t2 are different objects, so it returns false.