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

Quiz: Scheduling and Async · Question 7 of 10

What does this print? (code)

What does this print?

import java.util.concurrent.*;

public class Main {
    public static void main(String[] args) {
        CompletableFuture<Integer> a = CompletableFuture.supplyAsync(() -> 20);
        CompletableFuture<Integer> b = CompletableFuture.supplyAsync(() -> 22);
        int total = a.thenCombine(b, Integer::sum).thenApply(x -> x * 2).join();
        System.out.println(total);
    }
}
  1. A.42
  2. B.2022
  3. C.44
  4. D.84
Answer & explanation

Correct answer: 84

20 + 22 = 42, then doubled to 84; join() waits for the final result.

Can you get the rest right without peeking?

Take the timed Quiz: Scheduling and Async quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →