Skip to content
Sharp

Concurrency basics · interview question

Which scenario requires both 'volatile' and synchronization?

Multiple choiceHardchapter-15-curatedpremiumconcurrencythe-volatile-keyword
Choose one answer
Answer and explanation

Correct answer

D. Updating a shared object with multiple fields

Why

While 'volatile' can be used for a boolean flag, updating a shared object with multiple fields requires atomicity, which volatile alone does not provide. Synchronization is needed to ensure atomic updates.

Test yourself on Concurrency basics

A free test with instant, explained results. No account needed.

Start free test
All Concurrency basics questions →