Skip to content
Sharp

Object-oriented programming · interview question

In an e-commerce application, how can you safely expose a list of available products to a caller?

Multiple choiceMediumchapter-3-curatedpremiumoopdefensive-copying
Choose one answer
Answer and explanation

Correct answer

C. Return an unmodifiable view of the list

Why

Returning an unmodifiable view of the list via Collections.unmodifiableList provides the caller with a snapshot that cannot be modified, preserving the integrity and encapsulation of the original list.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →