Java OCA OCP Practice Question 378

Question

Which statement about ternary expressions is true?

  • A. In some cases, both expressions to the right of the conditional operator in a ternary expression will be evaluated at runtime.
  • B. Ternary expressions require parentheses for proper evaluation.
  • C. The ternary expressions are a convenient replacement for an if-then-else statement.
  • D. Ternary expressions support int and boolean expressions for the left-most operand.


C.

Note

Option A is incorrect as only one of the two right-hand expressions is evaluated at runtime.

Parentheses are helpful for reading ternary expressions but are not required, making Option B incorrect.

Option C is a correct statement about ternary operators as they are commonly used to replace short if-then-else statements.

Option D is incorrect as only boolean expressions are permitted in the left-most operand of a ternary expression.




PreviousNext

Related