Skip to content
Sharp

Object-oriented programming · interview question

Given a CartItem class and a Product class, how should CartItem access product details?

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

Correct answer

A. Through a reference to a Product object.

Why

A CartItem should have a reference to a Product object to access its details, promoting reuse and better 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 →