Language Upgrades · interview question
Given a sealed interface, which of the following is NOT a correct way to implement it?
Multiple choiceHardchapter-12-curatedpremiumlanguage-upgradessealed-classes
Answer and explanation
Correct answer
B. Using a non-sealed class that is not listed in the permits clause.
Why
A non-sealed class not listed in the permits clause cannot implement a sealed interface, as it violates the restrictions set by the permits clause, leading to a compilation error.
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?
- Why might an architect choose sealed classes for an e-commerce domain model?
- Consider the following code snippet. What will be the result of compiling this code?