← Quiz: Java Concurrency Utilities: all 10 questions
Quiz: Java Concurrency Utilities · Question 8 of 10
What does this print? (code)
What does this print?
import java.util.concurrent.atomic.*;
public class Main {
public static void main(String[] args) {
AtomicLong a = new AtomicLong(5);
long x = a.getAndAdd(3);
long y = a.addAndGet(3);
System.out.println(x + " " + y);
}
}
- A.8 11
- B.5 8
- C.5 11
- D.8 8
Answer & explanation
Correct answer: 5 11
getAndAdd returns the old value (5) and makes it 8; addAndGet returns the new value, 8 + 3 = 11.
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 →