← Quiz: Lambdas and Functional Interfaces: all 10 questions
Quiz: Lambdas and Functional Interfaces · Question 8 of 10
What does this print? (code)
What does this print?
import java.util.function.*;
public class Main {
static Supplier<String> greeter(String name) {
return () -> "Hi " + name;
}
public static void main(String[] args) {
Supplier<String> a = greeter("Asha");
Supplier<String> b = greeter("Om");
System.out.println(b.get() + ", " + a.get());
}
}
- A.Hi Asha, Hi Om
- B.Hi Om, Hi Asha
- C.Hi name, Hi name
- D.Compile error
Answer & explanation
Correct answer: Hi Om, Hi Asha
Each returned lambda remembers the name it was created with.
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 →