Why the bracket is not evaluated first in this Java program?

29 views Asked by At
public class Test {
    public static void main(String [] args) {
        String text = "GOOD ";
        text = text + (text = "LUCK ");
        System.out.println(text);
    }
}

According to operator precedence, the bracket should be evaluated first which would make the reference text to start pointing to the String "LUCK". Further it would concatenate with the same reference text and finally it should have printed "LUCK LUCK".

But it actually prints "GOOD LUCK". Can someone please explain, why is it so?

0

There are 0 answers