nerdexam
Oracle

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…

Utilizing Java Object-Oriented Approach

Question

Given the code fragment: abstract sealed interface Sint permits Story, Art { default String getTitle() { return "Book Title"; } } Which set of class definitions compiles?

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)
  • A
    15% (9)
  • B
    3% (2)
  • C
    73% (43)
  • D
    2% (1)
  • E
    7% (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 Story and Art are plain interfaces with no sealed/non-sealed modifier; permitted types cannot silently inherit from a sealed interface without declaring their own extensibility intent.
  • B - Story incorrectly extends sind (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 is class (lowercase), so Art won't compile.
  • E - Non-sealed (capital N) is not a valid Java modifier; the correct keyword is non-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

#sealed interfaces#permits clause#interface inheritance#declaration modifiers

Community Discussion

No community discussion yet for this question.

Full 1Z0-829 Practice