nerdexam
Oracle

1Z0-829 · Question #15

Given the directory structure: module1: p1\ Doc.java p2\ Util.java Given the definition of the Doc class: package p1; public sealed class Doc permits WordDoc { } Which two are valid definition of…

The correct answer is A. Package p1; Public non-sealed class wordDoc extends Doc () F. Package p1; Public final class wordDoc extends Doc (). Options A and F are valid because Java's sealed class specification requires every permitted subclass to explicitly declare one of three modifiers: final, sealed, or non-sealed. Option A uses non-sealed (allowing further subclassing) and Option F uses final (preventing…

Java Object-Oriented Approach

Question

Given the directory structure: module1: p1
Doc.java p2
Util.java Given the definition of the Doc class: package p1; public sealed class Doc permits WordDoc { } Which two are valid definition of the wordDoc class?

Options

  • APackage p1; Public non-sealed class wordDoc extends Doc ()
  • BPackage p1; Public class wordDoc extends Doc ()
  • CPackage p1; p2; Public non-sealed class WordDoc extends Doc ()
  • DPackage p1, p2; Public sealed class WordDoc extends Doc ()
  • EPackage p1, non-sealed abstract class WordDoc extends Doc ()
  • FPackage p1; Public final class wordDoc extends Doc ()

How the community answered

(35 responses)
  • A
    83% (29)
  • B
    3% (1)
  • C
    6% (2)
  • D
    9% (3)

Explanation

Options A and F are valid because Java's sealed class specification requires every permitted subclass to explicitly declare one of three modifiers: final, sealed, or non-sealed. Option A uses non-sealed (allowing further subclassing) and Option F uses final (preventing subclassing) - both satisfy this requirement and correctly place the class in package p1, matching where Doc was defined.

Option B is wrong because it omits the required final/sealed/non-sealed modifier entirely - a class extending a sealed class must declare one of these three.

Options C and D are wrong because Java does not allow multiple package declarations (package p1; p2; or package p1, p2; are both illegal syntax) - a class belongs to exactly one package, terminated by a semicolon.

Option E is wrong because it uses a comma instead of a semicolon after the package name (package p1, non-sealed...), making it syntactically invalid.

Memory tip: Think "FSN or fail" - every subclass of a sealed class must wear one of three badges: Final, Sealed, or Non-sealed. If the modifier is missing or the package syntax is broken, it's wrong.

Topics

#sealed classes#permitted subclasses#class modifiers#package scope

Community Discussion

No community discussion yet for this question.

Full 1Z0-829 Practice