Java Class Design Flashcards
7 cards from real 1Z0-811 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Java Class Design flashcards as text
What is the correct way to declare a singleton class in Java?
Answer: Make the constructor private and provide a static factory method
A singleton restricts instantiation by using a private constructor and a static method that returns the single instance.
Which statement about the `protected` access modifier is correct?
Answer: Protected members are accessible within the same package and by subclasses
`protected` grants access within the same package and to subclasses in any package.
What does it mean when a class is said to follow the 'is-a' relationship?
Answer: The class extends another class (inheritance)
An 'is-a' relationship is modeled by inheritance (`extends`), meaning the subclass IS-A type of the superclass.
In a class hierarchy, which constructor is called first when instantiating a deeply nested subclass?
Answer: The topmost superclass constructor (Object)
Constructor chaining ensures that the Object constructor executes first, followed by each superclass down to the instantiated subclass.
What is the result of calling an overridden method from the parent class constructor while instantiating a child class?
Answer: The child class version executes even before the child constructor body runs
Dynamic dispatch applies even during construction, so the child's overridden method runs, potentially before the child's fields are initialized.
Which of the following correctly describes a functional interface in Java 11?
Answer: An interface with exactly one abstract method
A functional interface has exactly one abstract method and can be annotated with `@FunctionalInterface`.
Which class do all Java classes implicitly extend if no explicit superclass is declared?
Answer: java.lang.Object
Every Java class implicitly extends `java.lang.Object` when no other superclass is specified.