Given:
and this code fragment:
What is the output?
equals(OraString) overloads Object.equals(Object) because its parameter type differs. Calling s2.equals("Moon") therefore resolves to the inherited equals(Object) method and performs reference equality, which is false for an OraString object and a String. The two identical string literals in s1 == "Moon" refer to the same interned object, so the first branch prints B. The field s2.s contains "Moon", making s1.equalsIgnoreCase(s2.s) true and causing C to print.
equals(OraString)
Object.equals(Object)
s2.equals("Moon")
equals(Object)
OraString
String
s1 == "Moon"
B
s2.s
"Moon"
s1.equalsIgnoreCase(s2.s)
C
Community Discussion