← Quiz: Abstract Classes and Interfaces: all 10 questions
Quiz: Abstract Classes and Interfaces · Question 10 of 10
What does this print? (code)
What does this print?
interface Op { int apply(int a, int b); }
public class Main {
public static void main(String[] args) {
Op add = (a, b) -> a + b;
Op mul = (a, b) -> a * b;
System.out.println(add.apply(2, 3) + mul.apply(2, 3));
}
}
- A.56
- B.5 6
- C.11
- D.Compile error
Answer & explanation
Correct answer: 11
Op has one abstract method, so lambdas can implement it. 5 + 6 = 11 (both are ints, so + adds them).
Can you get the rest right without peeking?
Take the timed Quiz: Abstract Classes and Interfaces quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →