Skip to content
Sharp

Language Upgrades · interview question

What happens if a subclass of a sealed class is not declared as final, sealed, or non-sealed?

Multiple choiceHardchapter-12-curatedpremiumlanguage-upgradessealed-classes
Choose one answer
Answer and explanation

Correct answer

D. The Java compiler will generate an error.

Why

If a subclass of a sealed class is not explicitly marked as final, sealed, or non-sealed, the Java compiler will generate an error. This ensures that all subclasses conform to the rules of the sealed hierarchy, maintaining control over the inheritance.

Test yourself on Language Upgrades

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

Start free test
All Language Upgrades questions →