Language Upgrades · interview question
In Java, what is one advantage of using sealed interfaces?
Multiple choiceEasychapter-12-curatedpremiumlanguage-upgradessealed-classes
Answer and explanation
Correct answer
D. They ensure that only specified classes can implement the interface.
Why
Sealed interfaces restrict which classes can implement them, similar to sealed classes. This ensures that only a predefined set of classes can provide implementations, helping maintain architectural integrity and preventing unauthorized implementations.
Test yourself on Language Upgrades
A free test with instant, explained results. No account needed.
More Language Upgrades questions
- Which of the following is NOT a valid modifier for a class extending a sealed class?
- How does pattern matching for 'instanceof' improve maintainability in Java?
- What must be true for a class to extend a sealed class and be marked as 'non-sealed'?
- Which Java keyword would you use to specify the classes that can extend a sealed class?
- Given a sealed interface, which of the following is NOT a correct way to implement it?
- Why might an architect choose sealed classes for an e-commerce domain model?