Bird
0
0

In a parking system, the enum SpotType is defined as { COMPACT, LARGE, HANDICAPPED }. A developer writes the code:

medium📝 Analysis Q6 of 15
LLD - Design — Parking Lot System
In a parking system, the enum SpotType is defined as { COMPACT, LARGE, HANDICAPPED }. A developer writes the code:
SpotType spot = SpotType.SMALL;

What is the issue with this code?
ACompilation error: SMALL is not a valid SpotType value.
BRuntime error: SMALL spot not found.
CCode compiles and runs, SMALL is added dynamically.
DNo issue, SMALL is treated as COMPACT.
Step-by-Step Solution
Solution:
  1. Step 1: Check enum values defined

    SpotType only has COMPACT, LARGE, HANDICAPPED; SMALL is not defined.
  2. Step 2: Understand enum value usage

    Using an undefined enum value causes compilation error in statically typed languages.
  3. Final Answer:

    Compilation error: SMALL is not a valid SpotType value. -> Option A
  4. Quick Check:

    Undefined enum value = compile error [OK]
Quick Trick: Use only defined enum values to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Assuming enums allow dynamic values
  • Expecting runtime errors instead of compile errors
  • Thinking undefined values map to existing ones

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes