Skip to content
Sharp

Core Java · interview question

In an e-commerce application, you have the following procedural code managing a list of products. What is a good candidate for refactoring this into an object-oriented design?

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

Correct answer

A. Create a Product class with fields for name and price.

Why

Refactoring into a Product class allows you to encapsulate the behavior and data related to a product. This makes the code more organized and aligns with object-oriented principles.

Test yourself on Core Java

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

Start free test
All Core Java questions →