Skip to content
Sharp

Language Upgrades · interview question

How does the 'sealed' keyword in Java differ from 'final'?

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

Correct answer

B. 'sealed' allows specific subclasses, 'final' does not allow any.

Why

The 'sealed' keyword allows specific subclasses to extend a class, whereas 'final' completely prohibits any subclassing. This provides a middle ground for controlling inheritance.

Test yourself on Language Upgrades

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

Start free test
All Language Upgrades questions →