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 effect of declaring a method `abstract` in a non-abstract class?
Answer: Compilation error — the class must also be abstract
A class containing an abstract method must itself be declared abstract, or a compile error results.
Which statement correctly describes constructor chaining using `this()`?
Answer: `this()` must be the first statement in the constructor
A `this()` constructor call must appear as the very first statement in the constructor body.
Which of the following best describes method overloading?
Answer: Same method name, different parameter lists in the same class
Overloading means defining multiple methods with the same name but different parameter signatures in the same class.
What does the `instanceof` operator return when the reference is null?
Answer: false
`null instanceof AnyType` always evaluates to `false` without throwing an exception.
In Java, a static nested class differs from an inner class because it:
Answer: Does not hold an implicit reference to the outer class instance
A static nested class has no implicit reference to the enclosing instance, unlike a non-static inner class.
Which of the following is a valid reason to use an abstract class instead of an interface?
Answer: To provide shared instance state (fields) and partial implementation
Abstract classes can hold instance fields and provide partial concrete implementation, which interfaces cannot do with state.
What is the output of the following code? ```java class A { void greet() { System.out.print("A"); } } class B extends A { void greet() { super.greet(); System.out.print("B"); } } public class T { public static void main(String[] a) { new B().greet(); } }```
Answer: AB
`super.greet()` prints "A" first, then the rest of B's greet prints "B", giving "AB".