This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
1) a = true is evaluated, so a = true 2) b = true is not evaluated, so b = false (short-circuit) 3) the original expresion would be, boolean x = true && (c = true) 4) c = true is evaluated, so c = true 5) boolean x = true
But the answer is, a = true, b = false, c = false Any ideas? Thanks a lot.
If you look at operator precedence order of || and &&, && has the higher precedence than operator ||. And also if you remember java always evaluates left oprand first for binary operators. So the expression will get evaluated as -
boolean x = (a = true) || (b = true) && (c = true);//Original expression.
x = ((a = true) || ((b = true) && (c = true)));//According to the precedence.