Skip to content
Sharp

Object-oriented programming · interview question

Given the following code, how do CartItem and Product communicate?

Multiple choiceMediumchapter-2-curatedpremiumoopobject-interaction
java
class Product { private double price; public double getPrice() { return price; } }
class CartItem { Product product; double getProductPrice() { return product.getPrice(); } }
Choose one answer
Answer and explanation

Correct answer

A. Through method calls from CartItem to Product.

Why

CartItem communicates with Product through method calls, which is a typical way for objects to interact 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 →