Skip to content
Sharp

Object-oriented programming · interview question

In a typical e-commerce application, how should a CartItem object access the price of a Product?

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

Correct answer

C. By using a public getter method in the Product class.

Why

A CartItem should access the Product price via a public getter method to adhere to encapsulation and ensure proper access control.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →