Skip to content
Sharp

Object-oriented programming · interview question

How can a 'Customer' object maintain a list of 'Cart' objects and ensure only one cart is active at a time?

Multiple choiceMediumchapter-2-curatedpremiumoopobject-references
Choose one answer
Answer and explanation

Correct answer

B. Use a method to deactivate all other carts when one is activated.

Why

To ensure only one cart is active at a time, a method can be implemented in the 'Customer' class to deactivate all other carts whenever a new one is activated. This ensures a single point of control for cart activation.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →