This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
When I'm executing the above piece of code, I'm getting the following output ---------- run ---------- str1.hashcode()15655788 str2.hashcode()-969099747 false Output completed (0 sec consumed) - Normal Termination
Ideally line no. 5 is attempting to compare two incompatible types, String and StringBufffer and should throw an error if we rewrite the line as
The line ("str1 == str2"+(str1 == str2)); returns false because you are comparing the references to two different objects. str1 points to a different object and str2 points to a different object in the memory. so the O/P false.
For the System.out.println("str1 == str2"+str1 == str2);, the compiler interprets it as, (("str1 == str2"+str1) == str2); bcos + has higher precedence than ==.
Regards, Jothi Shankar Kumar. S
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!