Operator Precedence in Java with brackets

Viewed 22

I have a below code snippet,

int a = 1,b = 2;
a = b + (b = a); // () have higher precedence, so it should be evaluated first
System.out.println(a); // Output - 3 but should be a = 1 + 1 = 2;

I cannot understand how operator precedence is working here. Since () have higher precedence, it should be implemented first and assign b = 1 and the output should be 2 but its output is 3. Please tell me where I am wrong!

0 Answers
Related