โ† All 1Z0-811 Flashcard Decks

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
  1. What is the key difference between overriding and hiding a method in Java?

    Answer: Overriding applies to instance methods; hiding applies to static methods

    Overriding uses dynamic dispatch for instance methods; static methods are hidden, meaning the reference type determines which version runs.

  2. When can a subclass override a parent method with a narrower (more specific) return type?

    Answer: When the return type is a subtype of the parent method's return type (covariant return)

    Java allows covariant return types: the overriding method may return a subtype of the parent method's declared return type.

  3. Which of the following access modifiers can be used on a top-level class declaration?

    Answer: public or package-private only

    Top-level classes can only be `public` or package-private (no modifier); `private` and `protected` are not allowed at the top level.

  4. What is the purpose of the `@Override` annotation in Java?

    Answer: It documents the intended override and lets the compiler catch signature mismatches

    `@Override` tells the compiler to verify that this method actually overrides a superclass or interface method, catching typos or signature errors.

  5. A local class declared inside a method can access which of the following from the enclosing method?

    Answer: Only effectively final local variables

    Local (and anonymous) classes can access local variables from the enclosing method only if they are effectively final.

  6. Which of the following is NOT a valid use of the `this` keyword in Java?

    Answer: Calling a static method on the current class

    Static methods belong to the class and are not invoked via an instance reference like `this`; they are called on the class name.

  7. What is an anonymous class in Java?

    Answer: A class that is declared and instantiated in a single expression, usually extending a class or implementing an interface

    An anonymous class is a local class without a name, declared and instantiated inline, typically to provide a one-off implementation.