← Quiz: Java Multithreading: all 10 questions
Quiz: Java Multithreading · Question 8 of 10
What does marking a field volatile guarantee?
What does marking a field volatile guarantee?
- A.That count++ on it is atomic
- B.That every thread sees the latest written value
- C.That only one thread can use it at a time
- D.That it can never be changed
Answer & explanation
Correct answer: That every thread sees the latest written value
volatile gives visibility, not atomicity. For a safe counter, use AtomicInteger or synchronized.
Can you get the rest right without peeking?
Take the timed Quiz: Java Multithreading quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →