AP CSA Unit 4.3: Array Initialization and Default Values Practice
Share
Unit 4, Section 4.3
Day 3 Practice • January 9, 2026
🎯 Focus: Array Creation and Default Values
Practice Question
Consider the following code segment:
int[] arr = new int[5];
arr[0] = 10;
arr[2] = 20;
arr[4] = 30;
System.out.println(arr[1] + arr[3]);
What is printed as a result of executing this code segment?
What This Tests: Section 4.3 covers array creation and access. When you create an array with
new, all elements are initialized to default values—0 for int, false for boolean, null for objects.Array State After Code Runs
| Index | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| After new | 0 | 0 | 0 | 0 | 0 |
| After assignments | 10 | 0 | 20 | 0 | 30 |
arr[1] + arr[3] = 0 + 0 = 0
Default Values
// Default values when using new:
int[] → 0
double[] → 0.0
boolean[] → false
String[] → null
Object[] → null
Common Mistakes
Mistake: Answer B (30)
This confuses indices. arr[4] = 30, but we're accessing arr[1] and arr[3], which were never assigned and remain 0.
Mistake: Answer D (Error)
No error! int arrays have default values of 0, so arr[1] and arr[3] are valid and equal to 0.
Two Ways to Create Arrays
Array Initialization
1. new keyword: int[] arr = new int[5]; → all zeros
2. Initializer list: int[] arr = {10, 20, 30}; → specified values
Difficulty: Medium • Time: 2 minutes • AP Skill: 3.D - Array access
Ready to Level Up Your AP CSA Skills?
Get personalized help or access our complete question bank
Premium Question Bank - Coming Soon! Schedule 1-on-1 Tutoring