LearnFrenzy
Sign in Take a free test

Records, Enums and Sealed Classes · Records, Enums and Sealed Classes MCQ · Question 18

Why a sealed switch needs no default branch Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 18 Back to Exercise

Why can a switch over a sealed interface omit default?

  • A default is always optional
  • B The compiler knows all permitted subtypes and checks that each is handled Correct
  • C Sealed types cannot be null
  • D Only records are allowed
Correct Answer: Option B

Adding a new subtype then produces compile errors where it is not handled.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links