🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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));
    }
}
  1. A.56
  2. B.5 6
  3. C.11
  4. 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 →