Skip to content
Sharp

Language Upgrades · interview question

What happens if a new subclass is added to a sealed class hierarchy but is not handled in an existing pattern matching switch expression?

Multiple choiceMediumchapter-12-curatedpremiumlanguage-upgradespattern-matching
Choose one answer
Answer and explanation

Correct answer

A. The code will not compile due to missing case handling.

Why

In a pattern matching switch expression, if all subclasses of a sealed class are not handled, the code will fail to compile, ensuring all cases are considered.

Test yourself on Language Upgrades

A free test with instant, explained results. No account needed.

Start free test
All Language Upgrades questions →