Skip to content
Sharp

Object-oriented programming · interview question

Which class should be responsible for calculating the total price of items in an e-commerce cart?

Multiple choiceMediumchapter-3-curatedpremiumoopobject-responsibility
Choose one answer
Answer and explanation

Correct answer

D. Cart

Why

The Cart class should be responsible for calculating the total price as it aggregates multiple CartItem instances. Keeping this behavior in the Cart ensures the logic is centralized and maintains encapsulation.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →