Hello, 34. Given the following declaration which of the following statements equals to true boolean b1 = true; boolean b2 = false; A) b1 == b2; B) b1 | | b2; C) b1 |& b2; D) b1 && b2; The answer to above questions is B...I think it should be B & D. Can someone explain.....
Jane Griscti
Ranch Hand
Joined: Aug 30, 2000
Posts: 3141
posted
0
Hi Mukti, The surest way to check the results of Mock questions is to write some code and see what happens
The short-circuit operators give the same results as the normal | and & operators. Hope that helps.
------------------ Jane The cure for boredom is curiosity. There is no cure for curiosity. -- Dorothy Parker
Hi Mukti, I fully agree with you. D should be "true" since "b1" evaluates to true and because of the short circuit operator, the whole expression becomes true!
Mukti Bajaj
Ranch Hand
Joined: Dec 11, 2000
Posts: 59
posted
0
Hi Vineet, The answer to the above question is only B and not D. As for boolean OR operators, | and | | if either or both operands are true,the result is true and you will get result false, only if both the operands are false. And for boolean AND operators, & and && if both the operands are true the result is true otherwise the result is false. So, I agree with Jane suggestions....of writing the code and checking. Good Luck! Mukti