Logical Operators in Java - Quiz

Total: 3 questions

1. 

The feature of the short-circuit operators.

The short-circuit of the && and || operators don't waste time on pointless evaluations. A short-circuit && evaluates the left side of the expression first (operand one), and if it resolves to false, the && operator doesn't evaluate the right side of the expression. The || operator is similar to the && operator, except that it evaluates to true if ONE of the operands is true. If the first operand in an OR operation is true, the result will be true, so the short-circuit || doesn't waste time looking at the right side of the equation.

2. 

How non-short-circuit logical operators work?

They are used in logical expressions like the && and || operators, but they always evaluate both sides of the expression.

3. 

What is the value of the expression !true & false in Java?

The unary ! operator has the highest precedence among the logical operators, so it is evaluated first: !true is false. Then false & false is evaluated, which is false. So the value of the whole expression is false.

Page 1 of 1