This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
HI Rama, First of all, one must clearly remember the precedence and then the associativity As of this case, the operators under discussion are & && | || The order of precedence is Bitwise / logical AND& Bitwise / logical OR| Conditional AND && Conditional OR ||
Case (1) System.out.println(false && true || true);//returns true Operators involved are && || In this && has highest precedence. So the expression would be evaluated as ((false && true) || true) (false || true) (true)
Case (2) System.out.println(false && true | true);//returns false Operators involved && | In this | has highest precedence. So the expression would be evaluated as (false && ( true | true)) (false && true) (false)
I hope this helps. Please do mail back if what I have understood is not you have asked for.
Only those who will risk going too far can possibly find out how far one can go !!!
1. I don't know if its a type, should it be || instead of |. Would it still return a boolean with |.? ANS: Yes! Its a type, u can use |. Yes it will return boolean with | 2. Assuming it was a type and it actually meant ||, k&b says:
No, u no need to assume, keep as it is
if (x>3) is false, no point in looking at the rest of the expression. 'cos during runtime it is evaluated as
3. which means, it solves the first operation from left to right and the result of it, it operates with the next one.
can someone shed some light on this?
S, it solvz first operation from left to right and the result, with that result proceed to next operator and the other operand. this is the way how it work.