AP Computer Science A Practice Quiz: Array Creation and Access
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 10 questions to check your progress.
Question 1 of 10
All Questions (10)
A) int[] numbers = new int[50];
B) int numbers = new int[50];
C) int[] numbers = new array[50];
D) int[] numbers = new int[];
Correct Answer: A
This correctly declares an array of integers named 'numbers' and uses the 'new' keyword to establish its length at 50. The syntax requires the data type, square brackets, a variable name, the 'new' keyword, the data type again, and the length in square brackets.
A) true
B) false
C) null
D) The value is uninitialized and will cause an error.
Correct Answer: B
When an array is created using the 'new' keyword, all its elements are initialized to the default value for that data type. The default value for the boolean data type is 'false'.
A) Using parentheses ( ) with the element's position
B) Using the 'get' keyword followed by the element's position
C) Using square brackets [ ] with the element's index
D) Iterating through the array until the element is found
Correct Answer: C
The provided content states that 'Square brackets [ ] are used to access and modify an element in a 1D array using an index.'
A) The length of an array can be increased if more elements need to be added.
B) An array can store values of different data types simultaneously.
C) The length of an array is established at creation and cannot be changed.
D) The elements of an array are not initialized until they are explicitly assigned a value.
Correct Answer: C
The content explicitly states, 'The length of an array is established at the time of creation and cannot be changed.' This is a fundamental characteristic of arrays.
A) prices(1) = 25.75;
B) prices[1] = 25.75;
C) prices.set(1, 25.75);
D) prices[2] = 25.75;
Correct Answer: B
Square brackets [ ] are used to modify an element in an array. The index for the second element is 1 (since indexing starts at 0). Therefore, prices[1] correctly targets the second element for modification.
A) String[] studentNames = new String[25];
B) int[] studentNames = new int[25];
C) String studentNames = new String[25];
D) String[] studentNames = new String[];
Correct Answer: A
Arrays are used to represent collections of related data of the same type. Since names are text, the 'String' data type is appropriate. The syntax 'String[]' declares an array of Strings, and 'new String[25]' correctly allocates space for 25 elements.
A) { , , 10, }
B) {null, null, 10, null}
C) {0, 0, 10, 0}
D) {10, 0, 0, 0}
Correct Answer: C
When the integer array 'data' is created with 'new', all 4 elements are initialized to the default value for int, which is 0. The subsequent line, 'data[2] = 10;', modifies only the element at index 2. The other elements remain at their default value of 0.
A) Because arrays can only store elements of different types.
B) Because the array's elements have not been initialized yet.
C) Because the length of an array is fixed at the time of creation and cannot be changed.
D) Because square brackets [ ] can only be used for accessing elements, not adding them.
Correct Answer: C
One of the core principles of arrays is that their size is immutable. Once an array is created with a specific length (e.g., 5, with indices 0-4), it is not possible to add a sixth element (at index 5) because that memory location does not exist for the array. The length is fixed.
A) ""
B) AP
C) Exam
D) null
Correct Answer: D
When the array 'words' is created, all its elements are initialized to the default value for the String object type, which is 'null'. The code assigns values to the elements at index 0 and index 2, but the element at index 1 is never modified, so it retains its default value of 'null'.
A) 0
B) 3
C) 42
D) The code will cause a compilation error.
Correct Answer: C
First, an integer array 'values' is created, and all elements are initialized to 0. Second, the element at index 3 is modified to hold the value 42. Finally, the variable 'result' is assigned the value of the element at index 3, which is 42.