An array of objects stores references, not the objects themselves. Each element must be individually constructed with new, and calling methods on an uninitialized element causes a NullPointerException.
Declaring and Populating
// Creates an array of 3 Student references -- all null!
Student[] roster = new Student[3];
// Each element must be separately constructed
roster[0] = new Student("Ana", 11);
roster[1] = new Student("Ben", 10);
roster[2] = new Student("Cara", 12);
Calling Methods on Array Elements
for (int i = 0; i < roster.length; i++) {
System.out.println(roster[i].getName()); // calls method on each Student
System.out.println(roster[i].getGrade());
}
⚠ NullPointerException Risk:new Student[3] creates 3 null references, NOT 3 Student objects. Accessing roster[0].getName() before assigning roster[0] = new Student(...) throws a NullPointerException.
📝 Practice Question 1
After Car[] lot = new Car[5];, which of the following is true?
📝 Practice Question 2
What error occurs when the following code runs?
Book[] shelf = new Book[3];
System.out.println(shelf[0].getTitle());
✅ Exam Tip: The AP exam distinguishes between creating the array and creating the objects. Always check whether elements have been initialized before methods are called on them.
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed.
Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Typically responds within 24 hours
✓
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Choosing a selection results in a full page refresh.
Opens in a new window.
4. The correct popup fires automatically based on the current page URL:
- AP CSP pages -> CSP popup
- AP Cyber pages -> Cybersecurity popup
- All other pages -> AP CSA popup (already live, but improved version here)
Klaviyo API Key: XbXGVC
Klaviyo List ID: UpYKgr (add all to same list for now; tag by course)
============================================================ -->
AP Computer Science A
Free Daily Practice Questions + Exam Tips
Join 134+ AP CSA students getting better scores with daily practice
✓Daily MCQ + FRQ practice delivered free
✓54.5% of Tanner’s students score 5s (national avg: 25.5%)
✓Exam week survival guide — free for subscribers
✓
You’re in!
Check your email for your first practice question.