Bird
Raised Fist0

You have a Null Object implementation but still get null pointer exceptions in your system. What is the most likely cause?

medium📝 Analysis Q14 of Q15
LLD - Behavioral Design Patterns — Part 2
You have a Null Object implementation but still get null pointer exceptions in your system. What is the most likely cause?
ASome parts of the code still use null instead of the Null Object
BThe Null Object throws exceptions intentionally
CThe Null Object does not implement the required interface
DThe Null Object caches null values incorrectly
Step-by-Step Solution
Solution:
  1. Step 1: Understand Null Object pattern goal

    It replaces null references to avoid null pointer exceptions.
  2. Step 2: Identify why exceptions still occur

    If some code still uses null directly, exceptions will happen despite Null Object presence.
  3. Final Answer:

    Some parts of the code still use null instead of the Null Object -> Option A
  4. Quick Check:

    Null Object must replace all nulls to avoid exceptions [OK]
Quick Trick: All nulls must be replaced by Null Object [OK]
Common Mistakes:
MISTAKES
  • Assuming Null Object throws exceptions
  • Ignoring interface implementation correctness
  • Confusing caching with Null Object usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes