Q:

Using str1==str2 in System.out.println prints only true or false but does not print any text written along with it

Here is what i am talking about:
package finalExample;

public class FinalExample {

public static void main(String args[]) {

    final String str1 = "str";
    final String str2 = "ing";

    String str11 = "str";
    String str22 = "ing";

    System.out.println("Using equals() for non final :" + str11.equals(str22));
    System.out.println("Using == for non final :" + (str11==str22));
    System.out.println("MAGIC Using == for non final :" + str11==str22);

    System.out.println("Using equals() for final :" + str1.equals(str2));
    System.out.println("Using == for final :" + (str1==str2));
    System.out.println("MAGIC Using == for final :" + str1==str2);
}

}
Output is:
Using equals() for non final :false
Using == for non final :false
false
Using equals() for final :false
Using == for final :false
false

Both MAGIC Statements are not printed. Why is it so?

A:

The + operator binds at a higher precedence than the == operator, so your expression is:
"MAGIC Using == for final :" + str1==str2
("MAGIC Using == for final :" + str1)==str2
(a new String object created for the comparison can't)==str2
false

A:

You are evaluating
"MAGIC Using == for non final :" + str11

which is a string, and then comparing with str2

