Skip to content
Sharp

Object-oriented programming · interview question

What issue might arise if a constructor directly assigns a mutable object without copying it?

Multiple choiceHardchapter-2-curatedpremiumoopconstructors
Choose one answer
Answer and explanation

Correct answer

D. It might violate encapsulation.

Why

Directly assigning a mutable object can violate encapsulation, as external changes to the object can affect the instance's state, leading to unpredictable behavior.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →