Bird
0
0

If a Board class holds a 2D array of Piece objects, what will be the output of accessing board[0][0].type if the position is empty?

medium📝 Analysis Q5 of 15
LLD - Design — Chess Game
If a Board class holds a 2D array of Piece objects, what will be the output of accessing board[0][0].type if the position is empty?
AThe type of the piece at that position
BAn error or null reference exception
CThe string 'empty'
DAn empty string
Step-by-Step Solution
Solution:
  1. Step 1: Understand empty board positions

    Empty positions usually hold null or None, not a Piece object.
  2. Step 2: Accessing property on null

    Accessing .type on null causes an error or exception in most languages.
  3. Final Answer:

    An error or null reference exception -> Option B
  4. Quick Check:

    Accessing property on null = error [OK]
Quick Trick: Null positions cause errors when accessing properties [OK]
Common Mistakes:
  • Assuming empty returns 'empty' string
  • Expecting default piece type
  • Ignoring null reference errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes