Java OCA OCP Practice Question 815

Question

Which of the following statements are true about Java operators and statements? (Choose two.)

  • A. Both right-hand sides of the ternary expression will be evaluated at runtime.
  • B. A switch statement may contain at most one default statement.
  • C. A single if-then statement can have multiple else statements.
  • D. The | and || operator are interchangeable, always producing the same results at runtime.
  • E. The ! operator may not be applied to numeric expressions.


B, E.

Note

The ternary ? : operator only evaluates one of the two right-hand expressions at runtime, so Option A is incorrect.

A switch statement may contain at most one optional default statement, making Option B correct.

A single if-then statement can have at most one else statement, so Option C is incorrect.

You can join if-then-else statements together, but each else requires an additional if-then statement.

The disjunctive | operator will always evaluate both operands, while the disjunctive short-circuit || operator will only evaluate the right-hand side of the expression if the left-hand side evaluates to false.

Option D is incorrect.

Option E is correct.

The logical complement ! operator may only be applied to boolean expressions, not numeric ones.




PreviousNext

Related