AP CSA 4.3 Exercise 2: Array Creation and Access Applied Practice

Unit 4: Data Collections · Lesson 4.3 · Exercise 2

Array Creation and Access: Applied Practice

Six scenarios on what new int[n] actually produces, where the legal indices stop, and why length is not the last index.

How this one is different

The exercise-1 editor asks you to create and fill an array. These six ask what the array contained before you filled it and which index throws.

Applied Practice

6 questions · scenario driven · every answer is recorded for your teacher

Question 1 of 6Apply
A program executes int[] counts = new int[5]; and immediately prints counts[3].
What is printed?
Incorrect. Every element has a value the moment the array exists.
Correct. Correct. Java zero-fills numeric arrays; false for boolean and null for object references.
Incorrect. Java does not expose uninitialized memory. This is a C habit, not Java behavior.
Incorrect. Index 3 is legal in an array of length 5, whose valid indices are 0 through 4.
Question 2 of 6Analyze
A student writes for (int i = 0; i <= arr.length; i++) to visit every element.
What happens and why?
Correct. Correct. The off-by-one between a count and a final index is the single most common array error.
Incorrect. It visits every element and then one that does not exist. Nothing is skipped.
Incorrect. It compiles. The bounds check happens at run time, not compile time.
Incorrect. It runs one iteration too many and fails on that iteration.
Question 3 of 6Apply
A program needs an array whose size is read from user input at run time.
Which statement is true?
Incorrect. Arrays have no resize operation. Growing one means creating a new array and copying.
Incorrect. Using n is exactly what new int[n] is for.
Incorrect. Array length is determined at creation time and can come from any int expression.
Correct. Correct. Both halves matter: the size is flexible at creation and immovable afterward. That immovability is the reason ArrayList exists.
Question 4 of 6Analyze
A String array is created with new String[3] and printed before anything is stored.
What does each element hold?
Incorrect. Printing is legal and prints the word null.
Incorrect. The empty string is a real String object. The array holds no object at all.
Correct. Correct. This is why calling a method on an unfilled element throws NullPointerException.
Incorrect. No characters exist. There is no String object to hold them.
Question 5 of 6Apply
Given int[] a = {4, 8, 15, 16, 23, 42};
Which expression gives the last element without hardcoding its position?
Incorrect. One past the end. This throws.
Correct. Correct, and it keeps working if the array literal changes length.
Incorrect. Java does not support negative indexing. This throws.
Incorrect. Arrays have no methods. length is a field, not a method call.
Question 6 of 6Evaluate
A method receives an array parameter and sets arr[0] = 99. The caller then prints its own array.
What does the caller see and why?
Correct. Correct. This is the practical consequence of reference semantics and it surprises students constantly.
Incorrect. Arrays are fully mutable. Only the length is fixed.
Incorrect. Arrays are ordinary parameters.
Incorrect. The reference is copied, not the array. Both names point at one object.

Where to go next

Get in Touch

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.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]