1Z0-829 · Question #35
Given the code fragment: abstract sealed interface Sint permits Story, Art { default String getTitle() { return "Book Title"; } } Which set of class definitions compiles?
The correct answer is C. Sealed interface Story extends Sint {} Non-sealed class Art implements Sint {}. Option C compiles because it correctly fulfills the sealed interface contract: sealed interface Story extends Sint {} uses the sealed modifier, and non-sealed class Art implements Sint {} uses non-sealed - every type listed in a permits clause must explicitly declare itself…
Question
Options
- Ainterface Story extends Sint {} interface Art extends Sint {}
- Bpublic interface Story extends sind {} public interface Art extends Sint {}
- CSealed interface Story extends Sint {} Non-sealed class Art implements Sint {}
- DNon-sealed interface Story extends Sint {} Class Art implements Sint {}
- ENon-sealed interface Story extends Sint {} Non-sealed interface Art extends Sint {}
How the community answered
(59 responses)- A15% (9)
- B3% (2)
- C73% (43)
- D2% (1)
- E7% (4)
Explanation
Option C compiles because it correctly fulfills the sealed interface contract: sealed interface Story extends Sint {} uses the sealed modifier, and non-sealed class Art implements Sint {} uses non-sealed - every type listed in a permits clause must explicitly declare itself sealed, non-sealed, or final, and C is the only option that does this with valid Java syntax for both types.
Why the distractors fail:
- A - Both
StoryandArtare plain interfaces with nosealed/non-sealedmodifier; permitted types cannot silently inherit from a sealed interface without declaring their own extensibility intent. - B -
Storyincorrectly extendssind(lowercase typo), which doesn't exist; additionally, neither type has the required modifier. - D -
Class(capital C) is not a Java keyword; the correct keyword isclass(lowercase), soArtwon't compile. - E -
Non-sealed(capital N) is not a valid Java modifier; the correct keyword isnon-sealed(all lowercase), making both declarations invalid.
Memory tip: "Every child of a sealed type must pick a lane" - sealed (keep restricting), non-sealed (open it back up), or final (dead end). No modifier = compile error, and keyword casing is exact in Java.
Topics
Community Discussion
No community discussion yet for this question.