← All 1Z0-819 Flashcard Decks

Functional Interfaces Flashcards

7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Functional Interfaces flashcards as text
  1. A lambda body attempts to modify a local variable declared in the enclosing method. What happens?

    Answer: A compilation error occurs because local variables captured by lambdas must be effectively final

    Local variables captured by a lambda must be final or effectively final; reassigning them causes a compile-time error.

  2. What does the keyword `this` refer to inside a lambda expression?

    Answer: The enclosing class instance

    Unlike anonymous classes, lambdas do not introduce a new scope; `this` refers to the enclosing class instance.

  3. Which statement is true about checked exceptions inside a lambda that implements `Runnable`?

    Answer: Checked exceptions must be caught or wrapped inside the lambda body

    Runnable.run() does not declare any checked exceptions, so a lambda implementing it must catch any checked exceptions internally.

  4. Which of the following is a valid `@FunctionalInterface`?

    Answer: An interface with one abstract method that does not override any Object method

    A functional interface must be an interface with exactly one abstract method that is not a re-declaration of an Object method.

  5. What is the result of compiling an interface annotated with `@FunctionalInterface` that declares two abstract methods?

    Answer: A compilation error is produced

    @FunctionalInterface causes the compiler to enforce the single-abstract-method constraint, producing an error if violated.

  6. Which scenario correctly demonstrates a functional interface used as a variable type for a lambda?

    Answer: Supplier s = () -> "hello";

    Supplier has a single SAM getAsString() that takes no arguments and returns a String, matching () -> "hello".

  7. A child interface inherits one abstract method from a parent interface and declares no new abstract methods. Can it be annotated with `@FunctionalInterface`?

    Answer: Yes — it still has exactly one abstract method (inherited), satisfying the SAM requirement

    An interface can be functional if it has exactly one abstract method, whether inherited or declared; the parent need not be annotated.