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

Quiz: Java Concurrency Utilities · Question 5 of 10

What does this print? (code)

What does this print?

import java.util.concurrent.*;
public class Main {
    public static void main(String[] args) {
        String r = CompletableFuture.supplyAsync(() -> 6)
            .thenApply(x -> x * 7)
            .thenApply(x -> "answer=" + x)
            .join();
        System.out.println(r);
    }
}
  1. A.answer=6
  2. B.answer=42
  3. C.answer=13
  4. D.It prints nothing because the task runs in the background
Answer & explanation

Correct answer: answer=42

join waits for the whole chain: 6, then 6 * 7 = 42, then the string.

Can you get the rest right without peeking?

Take the timed Quiz: Java Concurrency Utilities quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →