Skip to content
Sharp

Object-oriented programming · interview question

Given a CartItem class, why might it be beneficial to include a Product field within it?

Multiple choiceMediumchapter-2-curatedpremiumoopfields-and-state
Choose one answer
Answer and explanation

Correct answer

C. To associate the cart item with the specific product being bought

Why

Including a Product field allows each CartItem to be directly associated with the specific product being purchased, which is crucial for tracking cart contents and calculating total costs.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →