Bird
Raised Fist0

Given the following code snippet, what will be the output?

medium📝 Analysis Q4 of Q15
LLD - Design — Parking Lot System
Given the following code snippet, what will be the output?
class Spot {
  boolean isAvailable = true;
  void park() { isAvailable = false; }
}
Spot s = new Spot();
s.park();
System.out.println(s.isAvailable);
Afalse
Btrue
Cnull
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze initial state of isAvailable

    Initially, isAvailable is true.
  2. Step 2: Effect of park() method

    Calling park() sets isAvailable to false.
  3. Step 3: Output after park()

    Printing isAvailable after park() prints false.
  4. Final Answer:

    false -> Option A
  5. Quick Check:

    park() sets isAvailable false = B [OK]
Quick Trick: park() sets availability false, so output is false [OK]
Common Mistakes:
MISTAKES
  • Assuming isAvailable remains true
  • Confusing boolean default values
  • Thinking park() returns a value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes