← Quiz: Records and Sealed Classes: all 10 questions
Quiz: Records and Sealed Classes · Question 9 of 10
What is the main benefit of a switch over a sealed type (Java 21)?
What is the main benefit of a switch over a sealed type (Java 21)?
- A.It runs faster than if-else
- B.The compiler can check that every permitted subtype is handled, without a default
- C.It allows switching on any object without patterns
- D.It makes the subclasses mutable
Answer & explanation
Correct answer: The compiler can check that every permitted subtype is handled, without a default
Because the list of subtypes is closed, a missing case is a compile error.
Can you get the rest right without peeking?
Take the timed Quiz: Records and Sealed Classes quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →