Skip to content
Sharp

Language Upgrades · interview question

Which of the following is a primary benefit of using sealed classes in Java?

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

Correct answer

B. They limit the inheritance hierarchy to a controlled set of classes.

Why

Sealed classes in Java restrict which classes can extend or implement them, allowing developers to control the inheritance hierarchy. This is useful for maintaining strict control over the architecture and ensuring that only trusted classes are part of the hierarchy.

Test yourself on Language Upgrades

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

Start free test
All Language Upgrades questions →