Skip to content
Sharp

Object-oriented programming · interview question

Why might you create a method in the 'Product' class that returns a deep copy of a 'Product' object?

Multiple choiceMediumchapter-2-curatedpremiumoopobject-references
Choose one answer
Answer and explanation

Correct answer

C. To prevent changes to the original object when modifications are needed.

Why

Creating a method that returns a deep copy of a 'Product' object is useful when you want to make modifications without affecting the original object. This approach is common when you need to ensure immutability or independence of 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 →