Java SE 8 Programmer I — Question 58
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 mandatory.
- C. Its case label literals can be changed at runtime.
- D. Its expression must evaluate to a single value.
Correct answer: D
Explanation
The correct answer is D because the switch statement's expression must yield a single value for it to function correctly. Option A is incorrect since a default section is not mandatory, B is wrong as the break statement is not always required, and C is false because case label literals cannot be modified during runtime.