Skip to content
Sharp

Object-oriented programming · interview question

In the context of immutability, why is it important to make defensive copies of internal mutable objects?

Multiple choiceHardchapter-3-curatedpremiumoopaccess-modifiers-and-visibility
Choose one answer
Answer and explanation

Correct answer

C. To prevent external modification of the object's state

Why

Making defensive copies of internal mutable objects prevents external code from modifying the internal state of an object. This helps maintain immutability and ensures the object remains in a consistent state.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →