Skip to content
Sharp

Object-oriented programming · interview question

In the context of shared mutable state, which technique helps prevent data races in a multithreaded environment?

Multiple choiceHardchapter-3-curatedpremiumoopdefensive-copying
Choose one answer
Answer and explanation

Correct answer

C. Using immutable objects

Why

Using immutable objects in a multithreaded environment helps prevent data races because immutable objects cannot be altered once created. This eliminates the need for synchronization when accessing these objects.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →