Skip to content
Sharp

Object-oriented programming · interview question

Why can a ShoppingCart that directly modifies Product stock levels become a bug in practice?

Multiple choiceHardchapter-2-curatedpremiumoopobject-interaction
Choose one answer
Answer and explanation

Correct answer

B. It violates encapsulation and single responsibility principles.

Why

Directly modifying Product stock levels from ShoppingCart violates encapsulation and single responsibility, as stock management should be a responsibility of Product or a related service.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →