Java Sealed Interfaces Compilation Rules

Utilizing Java Object-Oriented Approach
Answer Correct answer: D — Using 'non-sealed' allows the interface to be implemented by any class, breaking the sealed constraint.

Given the code fragment: Which set of class definitions compiles? - image

  1. interface Story extends SInt {}
  2. public interface Story extends SInt {}
  3. sealed interface Story extends SInt {}
  4. non-sealed interface Story extends SInt {} Correct Answer
  5. non-sealed interface Story extends SInt {}

Community Votes

D
100%

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)

meltedolive 👍 6
Right option is D.
Tangaizw 👍 1
How is C wrong?
filledapril 👍 1
if option E is like: E. non-sealed interface Story extends SInt {} non-sealed class Art implements SInt {} , in this case should select the E
Uteman 👍 1
D is the correct answer non-sealed opens up for any class to implement
TrinhLK 👍 1
D is correct
minhdev 👍 2
D is correct, Sealed interface allows sealed, non-sealed interface extends it.
Samps 👍 4 Selected: D
Right answer is D
supersquax 👍 4
Right answer is D. E is missing "sealed", "non-sealed" or "final" modifier.
Tojose 👍 3
The right option is D. non-sealed interface Story extends SInt {} non-sealed interface Art extends SInt {}, because the class in option E require an modifier

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

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.

More 1Z0-829 FAQ →

Related Analysis

← Back to 1Z0-829 Study Guide