Skip to content
Sharp

Core Java · interview question

In an e-commerce application, a 'Customer' class has a 'getOrders()' method that returns a list of orders. What is a safe practice for handling this list?

Multiple choiceMediumchapter-3-curatedpremiumcore-javacode-reading-and-state-safety
Choose one answer
Answer and explanation

Correct answer

A. Return a copy of the list.

Why

Returning a copy of the list ensures that the original list cannot be modified externally, preserving the integrity of the 'Customer' class's internal state.

Test yourself on Core Java

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

Start free test
All Core Java questions →