Given the following:
What is the output?
The == operator compares object references, and the two Product constructor calls create distinct objects, so ans1 is false. String.equals() compares character content, and both name fields contain "Pen", so ans2 is true.
==
Product
ans1
false
String.equals()
name
"Pen"
ans2
true
Community Discussion