Bird
Raised Fist0

Which of the following is the correct way to represent a Menu item in a class?

easy🧠 Conceptual Q3 of Q15
LLD - Design — Food Delivery System
Which of the following is the correct way to represent a Menu item in a class?
Aclass MenuItem { String name; double price; }
Bclass Menu { List<String> items; }
Cclass Order { int quantity; }
Dclass Restaurant { String address; }
Step-by-Step Solution
Solution:
  1. Step 1: Identify the class representing a single menu item

    A MenuItem class should have properties like name and price.
  2. Step 2: Check the options

    class MenuItem { String name; double price; } correctly defines a MenuItem with name and price fields.
  3. Final Answer:

    class MenuItem { String name; double price; } -> Option A
  4. Quick Check:

    Menu item = name and price fields [OK]
Quick Trick: MenuItem class holds name and price, not the whole menu [OK]
Common Mistakes:
MISTAKES
  • Using Menu class for single item
  • Confusing Order with MenuItem
  • Missing price field in MenuItem

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes