Skip to content
Sharp

Object-oriented programming · interview question

In an e-commerce application, how would you ensure that a customer's address list cannot be modified after initialization?

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

Correct answer

D. Initialize it as an unmodifiable list

Why

To ensure that a customer's address list remains unchanged after initialization, you can initialize it as an unmodifiable list using Collections.unmodifiableList or List.copyOf. This prevents any external code from making changes to the 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 →