equals() checks if the two objects have the same value
a and b both refer to the same string literal, which was created in a special memory area called "String constant pool". Therefor a==b and b.equals(a) return true.
While c is a reference to an object created in the heap by the virtue of using the keyword "new". Th object is created in the heap with a new memory location, therefor == fails to succeed when comparing a==c or b==c.
|
Oracle Certified Professional Java Programmer
Author:
JavaChamp TeamSenior Java Developer
QuizOver.com
Germany
Access: |