Bird
0
0

Which of the following is the correct syntax to add a product to a cart in an object-oriented design?

easy📝 Conceptual Q3 of 15
LLD - Design — Online Shopping Cart
Which of the following is the correct syntax to add a product to a cart in an object-oriented design?
Acart.addProduct(product, quantity);
Bproduct.addToCart(cart, quantity);
Ccart.productAdd(product, quantity);
DaddProduct(cart, product, quantity);
Step-by-Step Solution
Solution:
  1. Step 1: Understand method ownership

    Adding a product to a cart should be a Cart class method, as it manages products.
  2. Step 2: Identify correct method call syntax

    Method name should be clear and follow common naming conventions like addProduct.
  3. Final Answer:

    cart.addProduct(product, quantity); is correct syntax -> Option A
  4. Quick Check:

    Method call = cart.addProduct(...) [OK]
Quick Trick: Cart manages products, so call addProduct on cart object [OK]
Common Mistakes:
  • Calling addToCart on product
  • Wrong method name productAdd
  • Using global function addProduct

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes