← 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);
}
}
- A.42
- B.2022
- C.44
- 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 →