Skip to content
Sharp

Object-oriented programming · interview question

If a Product class has a private field price, which method signature allows a CartItem to read it?

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

Correct answer

A. Public double getPrice()

Why

A public getPrice() method allows external classes, like CartItem, to access the price while maintaining 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 →