Skip to content
Sharp

Object-oriented programming · interview question

Which approach should be used to prevent modification of a list returned by a method?

Multiple choiceHardchapter-3-curatedpremiumoopobject-responsibility
Choose one answer
Answer and explanation

Correct answer

D. Return an unmodifiable list

Why

Returning an unmodifiable list ensures that the caller cannot modify the list. This approach enforces encapsulation by maintaining the integrity of the original list while providing read-only access.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →