Skip to content
Sharp

Language Upgrades · interview question

Why do teams use sealed classes in Java in production code?

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

Correct answer

D. Restricting the class hierarchy to improve security.

Why

Sealed classes allow you to restrict which classes can extend or implement them. This control helps maintain a fixed class hierarchy, preventing unauthorized or rogue subclassing.

Test yourself on Language Upgrades

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

Start free test
All Language Upgrades questions →