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
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)- A74% (25)
- B6% (2)
- C9% (3)
- D12% (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 -
defaultis optional; if omitted and no case matches, execution simply falls through the entire switch block. - C -
breakis optional, not mandatory. Without it, execution falls through to the next case, which is sometimes intentional (e.g., stacking cases that share logic). - D -
caselabels must be compile-time constants (literals orfinalvariables); 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.