QuestionQ22

Java Platform Module System

Given the following directory structure:

Question Image

Given the Doc class definition:

Question Image

Which two definitions of the WordDoc class are valid?

Choose three
  • A package p1.p2;public non-sealed class WordDoc extends Doc { }
  • B package p1;public final class WordDoc extends Doc {}
  • C package p1;non-sealed abstract class WordDoc extends Doc {}
  • D package p1.p2:public sealed class WordDoc extends Doc { }
  • E package p1;public class WordDoc extends Doc {}
  • F package p1;public non-sealed class WordDoc extends Doc {}
Explanation

permits WordDoc denotes p1.WordDoc. A direct subclass of a sealed class must explicitly be declared final, sealed, or non-sealed. Therefore, the final declaration and both non-sealed declarations in package p1 are valid. An abstract class may also be non-sealed; the Java Language Specification does not require such a permitted subclass to be public. The item consequently contains three valid choices, despite instructing the reader to choose two.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!