Java SE 8 Programmer I — Question 162
Which statement is true about the switch statement?
Answer options
- A. It must contain the default section.
- B. The break statement, at the end of each case block, is optional.
- C. Its case label literals can be changed at runtime.
- D. Its expression must evaluate to a collection of values.
Correct answer: B
Explanation
The correct answer is B because the break statement is optional; omitting it allows execution to continue into the next case. Option A is incorrect as the default section is not mandatory. Option C is wrong because case labels are fixed at compile time and cannot be changed at runtime. Option D is also incorrect since the expression must evaluate to a single value, not a collection.