Skip to content
Sharp

Object-oriented programming · interview question

Consider a 'CartItem' class with a field 'quantity'. How might changing the 'quantity' field affect object behavior?

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

Correct answer

D. It could change the total price calculation

Why

The 'quantity' field in a 'CartItem' class affects the total price calculation for that item in the cart. A change in quantity should lead to a recalculation of the total cost to reflect the new order size.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →