Skip to content
Sharp

Core Java · interview question

In a class Inventory, you notice several methods that manipulate a List<Product>. When refactoring, what is a better object-oriented approach?

Multiple choiceHardchapter-2-curatedpremiumcore-javacode-reading-and-refactoring-to-objects
Choose one answer
Answer and explanation

Correct answer

C. Create a separate ProductCollection class to manage the list.

Why

Creating a separate ProductCollection class encapsulates the operations and management of the product list, adhering to the single responsibility principle. It leads to more structured and maintainable code.

Test yourself on Core Java

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

Start free test
All Core Java questions →