nerdexam
Oracle

1Z0-809 · Question #228

Given: ``java interface P { public void method1(); } interface Q extends P { public void method1(); } interface R extends P { public void method2(); } interface S { public default void method1() { }…

The correct answer is A. T F. U. There appears to be an error in the provided answer key. Based on Java's definition of a functional interface, the actual correct answers are C (P) and E (Q), not A and F. Why C (P) and E (Q) are correct: A lambda expression requires a functional interface - one with exactly…

Question

Given:
interface P { public void method1(); }
interface Q extends P { public void method1(); }
interface R extends P { public void method2(); }
interface S { public default void method1() { } }
interface T { public void method1(); public void method2(); }
interface U { public void method1(); public abstract void method2(); }
Which two interfaces can you use to create lambda expressions? (Choose two.)

Options

  • AT
  • BR
  • CP
  • DS
  • EQ
  • FU

How the community answered

(45 responses)
  • A
    71% (32)
  • B
    4% (2)
  • C
    2% (1)
  • D
    7% (3)
  • E
    16% (7)

Explanation

There appears to be an error in the provided answer key. Based on Java's definition of a functional interface, the actual correct answers are C (P) and E (Q), not A and F.

Why C (P) and E (Q) are correct: A lambda expression requires a functional interface - one with exactly one abstract method (SAM: Single Abstract Method). P declares a single abstract method (method1), making it a valid SAM type. Q extends P and redeclares method1, which doesn't add a second abstract method - it simply overrides the same one, so Q also has exactly one abstract method and qualifies.

Why the others are wrong:

  • R inherits method1 from P and adds method2, giving it two abstract methods - not a functional interface.
  • S has zero abstract methods (method1 is default), so there's nothing for the lambda to implement.
  • T explicitly declares method1 and method2 - two abstract methods, disqualifying it.
  • U is identical in effect to T: public void and public abstract void mean the same thing in interfaces - still two abstract methods.

Memory tip: Think "SAM = lambda." Count abstract methods only - default and static methods don't count, and re-declaring an inherited method doesn't add a new one. If the count isn't exactly 1, the interface can't be a lambda target.

Note: If this is from an official source, double-check the answer key - T and U both have two abstract methods and are definitively not functional interfaces under the Java Language Specification.

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice