LearnFrenzy
Sign in Take a free test

Control Flow Statements · Control Flow MCQ · Question 6

When does a switch expression need default? Answer, explanation & discussion

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

When can a switch expression over an enum omit default?

  • A Never
  • B When it has a case for every enum constant (it is exhaustive) Correct
  • C Always
  • D Only for String switches
Correct Answer: Option B

The same applies to a sealed type whose permitted subtypes are all covered.

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