🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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)?

  1. A.It runs faster than if-else
  2. B.The compiler can check that every permitted subtype is handled, without a default
  3. C.It allows switching on any object without patterns
  4. 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 →