AP Computer Science A Practice Quiz: 2D 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[][] grades = new int[10][5];
B) int grades[][] = new int[5][10];
C) int[10][5] grades = new int[][];
D) int[][] grades = new int[];
Correct Answer: A
The correct syntax for creating a 2D array is `type[][] arrayName = new type[rows][columns];`. Option A correctly specifies 10 for the number of rows (the first index) and 5 for the number of columns (the second index).
A) words[1][1]
B) words[2][2]
C) words[1, 1]
D) words[e]
Correct Answer: A
2D arrays are accessed using the format `[row][col]`. Since array indexing is 0-based, the element "e" is located in the second row (index 1) and the second column (index 1). Therefore, `words[1][1]` is the correct expression.
A) matrix.length
B) matrix[0].length
C) matrix.length()
D) matrix[25].length
Correct Answer: A
For a 2D array, the `length` attribute of the array object itself provides the number of rows. `matrix.length` will correctly evaluate to 25.
A) board.length
B) board[0].length
C) board.length[0]
D) board[].length
Correct Answer: B
A 2D array is an array of arrays. To find the number of columns, you must first access one of the inner arrays (a row, such as `board[0]`) and then get its `length` attribute.
A) A single, contiguous block of memory organized as a grid.
B) An array where each element is a reference to another array.
C) A special object that can dynamically change its number of rows and columns.
D) A collection that stores key-value pairs in a grid format.
Correct Answer: B
The provided content explicitly states, 'A 2D array is stored as an array of arrays.' This means the outer array contains elements that are references to the inner arrays (the rows).
A) 20
B) 30
C) 40
D) 99
Correct Answer: D
The statement `data[1][0] = 99;` uses the square brackets `[row][col]` to access the element at row index 1 and column index 0 (which is initially 30) and modifies its value to 99. The subsequent print statement outputs this new value.
A) The number of rows can be changed to 6 after creation.
B) The number of columns in the first row can be changed to 7.
C) The size of the `grid` is established at creation and cannot be changed.
D) New rows can be added, but existing rows cannot be resized.
Correct Answer: C
The provided content states, 'The size of a 2D array is established at the time of creation and cannot be changed.' This means that both the number of rows and the number of columns are fixed once the array is instantiated.
A) Only primitive data can be stored.
B) Only object reference data can be stored.
C) Both primitive `char` data and `String` objects can be stored.
D) The array can store any type of object reference, such as `Integer` or `Double`.
Correct Answer: B
The array is declared with the type `String`, which is an object. Therefore, it can only hold references to `String` objects. The content states that 2D arrays can store either primitive data or object reference data, and the type is fixed upon declaration.
A) "Hist"
B) "Eng"
C) "Lang"
D) "Study"
Correct Answer: C
`schedule.length` evaluates to 3, which is the number of rows. Therefore, `schedule.length - 1` is 2. The expression simplifies to `schedule[2][0]`, which accesses the element at the last row (index 2) and the first column (index 0). This element is "Lang".
A) 5
B) 10
C) 15
D) 30
Correct Answer: C
The code first initializes `matrix[0][0]` to 5 and `matrix[1][1]` to 10. The third line accesses these values and modifies `matrix[0][1]`, calculating `matrix[0][1] = 5 + 10`, which results in 15. The fourth line modifies a different element (`matrix[1][0]`), so the value of `matrix[0][1]` remains 15.