🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Lambdas and Functional Interfaces: all 10 questions

Quiz: Lambdas and Functional Interfaces · Question 1 of 10

What does this print? (code)

What does this print?

import java.util.function.*;
public class Main {
    public static void main(String[] args) {
        Function<Integer, Integer> f = x -> x + 1;
        Function<Integer, Integer> g = x -> x * 2;
        System.out.println(f.andThen(g).apply(5) + " " + f.compose(g).apply(5));
    }
}
  1. A.11 12
  2. B.12 11
  3. C.12 12
  4. D.11 11
Answer & explanation

Correct answer: 12 11

andThen: (5 + 1) * 2 = 12. compose runs g first: 5 * 2 + 1 = 11.

Can you get the rest right without peeking?

Take the timed Quiz: Lambdas and Functional Interfaces quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →