Bird
0
0

Why does the following implementation cause a compilation error?

medium📝 Analysis Q7 of 15
LLD - Design — Parking Lot System
Why does the following implementation cause a compilation error?
class NearestSpotStrategy implements ParkingStrategy {
  public ParkingSpot findSpot() {
    // missing vehicle parameter
    return findClosestFreeSpot();
  }
}
AMethod signature does not match interface requiring a vehicle parameter.
BThe method returns void instead of ParkingSpot.
CThe class does not implement the interface.
DThe method is private instead of public.
Step-by-Step Solution
Solution:
  1. Step 1: Check interface method signature

    The interface requires findSpot(Vehicle vehicle) but method lacks parameter.
  2. Step 2: Understand the compilation impact

    Mismatch causes compilation error due to method signature conflict.
  3. Final Answer:

    Method signature does not match interface requiring a vehicle parameter. -> Option A
  4. Quick Check:

    Signature mismatch = compilation error [OK]
Quick Trick: Method signature must match interface exactly [OK]
Common Mistakes:
MISTAKES
  • Ignoring missing parameters
  • Confusing return type errors
  • Assuming access modifier causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes