Bird
Raised Fist0

Which of the following is the correct method signature for a parking strategy's spot finding function in Java?

easy🧠 Conceptual Q3 of Q15
LLD - Design — Parking Lot System
Which of the following is the correct method signature for a parking strategy's spot finding function in Java?
AParkingSpot findSpot();
Bvoid findSpot(Vehicle vehicle);
Cpublic void findSpot();
Dpublic ParkingSpot findSpot(Vehicle vehicle);
Step-by-Step Solution
Solution:
  1. Step 1: Understand method purpose

    The method must return a ParkingSpot and accept a Vehicle to decide the spot.
  2. Step 2: Check method signatures

    public ParkingSpot findSpot(Vehicle vehicle); returns ParkingSpot and takes Vehicle parameter, matching the requirement.
  3. Final Answer:

    public ParkingSpot findSpot(Vehicle vehicle); -> Option D
  4. Quick Check:

    Correct signature returns spot and takes vehicle [OK]
Quick Trick: Method must return spot and accept vehicle [OK]
Common Mistakes:
MISTAKES
  • Missing return type
  • No vehicle parameter
  • Void return type when spot needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes