Java OCA OCP Practice Question 480

Question

Which statement about the logical operators & and && is true?

  • A. The & and && operators are interchangeable, always producing the same results at runtime.
  • B. The & operator always evaluates both operands, while the && operator may only evaluate the left operand.
  • C. Both expressions evaluate to true if either operand is true.
  • D. The & operator always evaluates both operands, while the && operator may only evaluate the right operand.


B.

Note

The & and && (AND) operators are not interchangeable.

The conjunctive & operator always evaluates both sides of the expression.

The conditional conjunctive && operator only evaluates the right-hand side of the expression if the left side is determined to be true.

This is why conditional operators are often referred to as short-circuit operators, skipping the right-hand side expression at runtime.

For these reasons, Option B is the correct answer.

Note that Option C is an incorrect statement as well, since it describes disjunctive (OR) operators.




PreviousNext

Related