🎙 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 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());
    }
}
  1. A.Hi Asha, Hi Om
  2. B.Hi Om, Hi Asha
  3. C.Hi name, Hi name
  4. 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 →