Hello i have a question regarding precedence Table in java. It says && has a higher precedence over ||.
boolean b,c,d;
b = c = d = false;
boolean e = (b = true) || (c = true) && (d = true);
System.out.println(b+" "+c+" "+d);
When i run mentioned code code it output "true false false". why doesn't it evaluate c = true && d = true part first since && has a higher precedence? Thanks in advance
The precedence here just means that
X || Y && Z
is equivalent to:
X || (Y && Z)
That executes as:
true
, the result is true
Y
Y
is false, the result of Y && Z
is false
, so the overall result is false
Z
true
, then Y && Z
is true
, so the overall result is true
false
, then Y && Z
is false
, so the overall result is `falseSee more on this question at Stackoverflow