Skip to content
Sharp

Core Java · interview question

In an e-commerce application, how can encapsulation improve the design of a class representing a shopping cart?

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

Correct answer

D. By hiding internal details and exposing only necessary interfaces.

Why

Encapsulation improves design by hiding the internal details of a class and exposing only the necessary interfaces. This approach ensures controlled access to the class's data, reducing dependencies and potential errors.

Test yourself on Core Java

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

Start free test
All Core Java questions →