← 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);
}
}
- A.answer=6
- B.answer=42
- C.answer=13
- 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 →