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
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)- A71% (32)
- B4% (2)
- C2% (1)
- D7% (3)
- E16% (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
method1fromPand addsmethod2, giving it two abstract methods - not a functional interface. - S has zero abstract methods (
method1isdefault), so there's nothing for the lambda to implement. - T explicitly declares
method1andmethod2- two abstract methods, disqualifying it. - U is identical in effect to T:
public voidandpublic abstract voidmean 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.