AP CSA Unit 3 Day 21: Null Reference
Share
Unit 3, Classes & Objects • Cycle 2
Day 21 Advanced Practice • Harder Difficulty
Focus: Null Reference
Hard
Null Reference
Advanced Practice Question
Format: Null Reference
What is the output?
What is the output?
public class Node {
private int data;
public int getData() {
return data;
}
}
// In another class:
Node n = null;
System.out.println(n.getData());
Difficulty: Hard |
Topic: Null Reference |
Cycle: 2 (Advanced)
Why This Answer?
Calling a method on a null reference causes a NullPointerException at runtime.
Common Mistake
Watch Out!
Thinking null has default values for its instance variables.
AP Exam Strategy
Null = no object. Can't call methods on nothing → NullPointerException.
Master This Topic
This Cycle 2 HARD question tests null reference. Review Unit 3 concepts to build mastery of classes & objects.
- Understanding null reference
- Tracing code execution accurately
- Avoiding common pitfalls
Ready for More Challenges?
Cycle 2 questions prepare you for the hardest AP CSA exam questions.
Study Games Practice FRQs