← 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));
}
}
- A.11 12
- B.12 11
- C.12 12
- 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 →