Java Sealed Interfaces Compilation Rules
Given the code fragment: Which set of class definitions compiles? - 
Community Votes
100% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The core trap is forgetting that any class or interface extending a sealed type must explicitly declare its own sealing status using 'sealed', 'non-sealed', or 'final'.
This question tests the strict syntax requirements for Java sealed interfaces, specifically the mandatory modifiers (sealed, non-sealed, or final). It establishes that a sealed interface cannot be extended by an unmodified interface.
Learners often select option C ('sealed interface') because they assume all extensions of a sealed interface must also be sealed. However, this restricts inheritance to only permitted subclasses, whereas the goal is often to allow broader implementation.
Community Discussion (9 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
Option D compiles because it uses the 'non-sealed' modifier, which allows any other class or interface in the module to implement or extend the 'Story' interface without restriction. This is a valid way to break the sealed hierarchy and permit open inheritance.Why the Other Options Are Wrong
Option A fails because it lacks a sealing modifier; extending a sealed type requires an explicit modifier. Option B is incorrect for the same reason as A, despite being public. Option C is syntactically correct but likely not the intended answer if the context implies opening the hierarchy, though strictly speaking, it does compile if 'Art' is also defined correctly. However, based on the options provided in the image context (which usually pairs Story and Art), Option E (often cited as missing modifiers in comments) is invalid. The key distinction is that 'non-sealed' opens the API.Community Comment Notes
Community consensus strongly supports D. Users like 'supersquax' and 'Tojose' note that option E (in some versions) misses necessary modifiers. 'minhdev' clarifies that 'non-sealed' is required to allow external classes to implement the interface, while 'Uteman' confirms that 'non-sealed' opens up inheritance for any class.Exam Strategy
When dealing with sealed types, always check if the subclass/interface needs to preserve the seal ('sealed'), break it completely ('non-sealed'), or close it ('final'). If the question asks for a definition that allows any class to implement, choose 'non-sealed'.
Frequently Asked Questions
Why can't I use 'sealed' for the implementing interface?
You can, but it restricts further extension to only the permitted subclasses listed in the permits clause. Use 'non-sealed' to allow unrestricted implementation.
Is 'public' required for a sealed interface?
No, 'public' is optional. The critical requirement is the sealing modifier (sealed, non-sealed, or final) when extending another sealed type.