nerdexam
Oracle

1Z0-809 · Question #127

Which statement is true about the switch statement?

The correct answer is A. Its expression must evaluate to a single value. Option A is correct because a switch statement evaluates its controlling expression to produce a single discrete value (an integer, character, string, or enum), which is then compared against each case label - it cannot branch on ranges, booleans, or complex conditions the way…

Question

Which statement is true about the switch statement?

Options

  • AIts expression must evaluate to a single value.
  • BIt must contain the default section.
  • CThe break statement, at the end of each case block, is mandatory.
  • DIts case label literals can be changed at runtime.

How the community answered

(34 responses)
  • A
    74% (25)
  • B
    6% (2)
  • C
    9% (3)
  • D
    12% (4)

Explanation

Option A is correct because a switch statement evaluates its controlling expression to produce a single discrete value (an integer, character, string, or enum), which is then compared against each case label - it cannot branch on ranges, booleans, or complex conditions the way an if-else chain can.

Why the distractors are wrong:

  • B - default is optional; if omitted and no case matches, execution simply falls through the entire switch block.
  • C - break is optional, not mandatory. Without it, execution falls through to the next case, which is sometimes intentional (e.g., stacking cases that share logic).
  • D - case labels must be compile-time constants (literals or final variables); they cannot be changed or computed at runtime.

Memory tip: Think of switch as a lookup table - it takes one key (the single value) and finds the matching row (case). A table lookup always needs exactly one key, keys are fixed at compile time, and you choose whether to stop at a row (break) or keep reading down (fall-through).

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice