The Java programming language also guarantees that every operand of an operator (except the conditional operators &&, ||, and ? appears to be fully evaluated before any part of the operation itself is performed.
At run time, the left-hand operand expression is evaluated first; if the result has type Boolean, it is subjected to unboxing conversion (�5.1.8); if the resulting value is true, the value of the conditional-or expression is true and the right-hand operand expression is not evaluated.
Java hobbyist.
Originally posted by Phalguni Bhatt:
Hi Neo Chap
code:
--------------------------------------------------------------------------------
boolean x = (d = true) || (e = true) && (f = true);
--------------------------------------------------------------------------------
Here first expressions are evaluated from left to right. So this code is trying to assign value to x. But as (d=true) is in brackets, value true is assigned to d first which was having default false. Then same true is assigned to x. Then || operator comes into execution. But as first condition is true, it doesn't bother to check right hand side expressions.
HTH
Phalguni
Java hobbyist.
Java hobbyist.
Java hobbyist.
Java hobbyist.
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|