Skip to content
Sharp

Object-oriented programming · interview question

In a class design, why might you choose to use an immutable object for sensitive data?

Multiple choiceHardchapter-3-curatedpremiumoopinvariants-and-validation
Choose one answer
Answer and explanation

Correct answer

B. To prevent unauthorized changes after creation

Why

Using an immutable object for sensitive data prevents unauthorized changes to the data once the object is created. This ensures that the data remains consistent and secure throughout its lifetime, making it particularly useful for maintaining invariants and handling sensitive information.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →