Java FPT Software (Fsoft) Academy Practice Test

Access More Questions
Which statement about volatile variables is false?
Correct Answer:
They guarantee atomicity for compound actions.
Explanation:
Volatile variables are about visibility across threads and the ordering of memory operations. When a thread writes to a volatile field, that write becomes visible to other threads that read that same field, and the JVM establishes a happens-before relationship: a write to a volatile happens-before every subsequent read of that volatile. This also helps prevent certain reordering around that access, so the sequence of reads and writes appears in a consistent order relative to the volatile access. But volatile does not guarantee atomicity for compound actions. If you perform a read-modify-write sequence (like counter++), those steps can interleave with other threads and lead to lost updates even with the variable marked volatile. For true atomicity, you need synchronization or atomic classes such as AtomicInteger. So the statement claiming atomicity for compound actions is the false one; the others correctly describe visibility, happens-before, and ordering guarantees provided by volatile.

Access more questions from this quiz

Continue to Java FPT Software (Fsoft) Academy Practice Test for more practice questions and the full quiz experience.

Access More Questions