1Z0-808 practice question 15 of 30
Which statement is true about the switch statement?
Full set: 224 questionsThe switch statement evaluates an expression and executes code blocks based on matching case labels. The break statement is used to exit the switch block. If a break is omitted from a case, execution "falls through" to the next case block. This behavior is intentional and well-defined, making the break statement optional. The other statements describe incorrect constraints or behaviors of the switch statement.
A. It must contain the default section.: The default section is optional. It executes only if no other case label matches the expression's value.
C. Its case label literals can be changed at runtime.: Case labels must be compile-time constant expressions of a type compatible with the switch expression.
D. Its expression must evaluate to a collection of values.: The switch expression must evaluate to a single value of type char, byte, short, int, String, or an enum.
- The Java® Language Specification, Java SE 8 Edition, Section 14.11, "The switch Statement". It details the syntax and semantics, including the optional nature of break and default.
- Oracle, The Java™ Tutorials, "The switch Statement". This guide explicitly states, "The break statements are necessary because without them, statements in switch blocks fall through...". This implies they can be omitted to achieve fall-through.
Keep practicing
Take the free 1Z0-808 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 1Z0-808 practice questions
- Question 2Which three statements are true about the structure of a Java class? (Choose three.)
- Question 3Which three statements are true about exception handling? (Choose three.)
- Question 9Which two are benefits of polymorphism? (Choose two.)
- Question 28Which statement is true about the main() method?
- Question 29Given the class definitions: class C1 {} class C2 extends C1 {} class C3 extends C2 {} an…
