Bird
Raised Fist0

Given the enum SpotType { COMPACT, LARGE, HANDICAPPED } and a function that assigns spots based on vehicle type, what will be the output of this code snippet?

medium📝 Analysis Q13 of Q15
LLD - Design — Parking Lot System
Given the enum SpotType { COMPACT, LARGE, HANDICAPPED } and a function that assigns spots based on vehicle type, what will be the output of this code snippet?
VehicleType vehicle = VehicleType.CAR;
SpotType spot;
switch(vehicle) {
  case VehicleType.CAR:
    spot = SpotType.COMPACT;
    break;
  case VehicleType.BIKE:
    spot = SpotType.HANDICAPPED;
    break;
  default:
    spot = SpotType.LARGE;
}
print(spot);
AError: VehicleType not handled
BHANDICAPPED
CCOMPACT
DLARGE
Step-by-Step Solution
Solution:
  1. Step 1: Identify vehicle type value

    VehicleType is set to CAR.
  2. Step 2: Follow switch-case logic

    For CAR, spot is assigned COMPACT.
  3. Final Answer:

    COMPACT -> Option C
  4. Quick Check:

    CAR maps to COMPACT spot [OK]
Quick Trick: Match enum cases carefully in switch [OK]
Common Mistakes:
MISTAKES
  • Confusing BIKE case with CAR
  • Assuming default runs for CAR
  • Ignoring break statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes