I wonder why the || operator is excetuted before && operator..:?? class A { static boolean a; static boolean b; static boolean c; public static void main (String[] args) { boolean x = (a = true) || (b = true) && (c = true); System.out.print(a + "," + b + "," + c); } } The result is true, false, false. P.S This question is from Dan's mock exam, they are really helpful, thanks, Dan.
P.S This question is from Dan's mock exam, they are really helpful, thanks, Dan.
You're welcome. That question seems to be a popular one here at the ranch.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
John Lee
Ranch Hand
Joined: Aug 05, 2001
Posts: 2545
posted
0
Originally posted by TTT^O^TTT ^O^: I wonder why the || operator is excetuted before && operator..:?? class A { static boolean a; static boolean b; static boolean c; public static void main (String[] args) { boolean x = (a = true) || (b = true) && (c = true); System.out.print(a + "," + b + "," + c); } } The result is true, false, false. P.S This question is from Dan's mock exam, they are really helpful, thanks, Dan.
The question is not why, it is why not. || and && has equal precedence, so it start from left to right.