• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar

JavaTutorOnline

1-on-1 Online Java Training by a Senior Software Engineer

  • Home
  • AP CSA
    • FRQ Practice
      • Arrays
      • ArrayList
      • Strings
      • 2D Arrays
    • MCQ Practice
      • Arrays
  • Courses
  • Tutorials
    • Java
    • Servlets
    • Struts
    • Spring
    • Webservice
  • FAQ
  • Testimonials
  • Blog
  • CONTACT US

AP CSA Unit 6 Practice: Array Creation and Access MCQs

Home » AP CSA MCQ » Unit 6

AP CSA Practice: Array Creation & Access

📚 Topic 6.1 ⏱️ 10 Min Practice ✅ Updated for 2027 Exam

Mastering arrays is one of the most critical steps in scoring a 5 on the AP Computer Science A exam. Unit 6 introduces the fundamental concepts of how Java allocates memory for data structures. Before you can write complex sorting algorithms, you must understand exactly how arrays are created, initialized, and accessed.

In this interactive practice set, we cover Topic 6.1: Array Creation and Access. These 10 multiple-choice questions are designed to mirror the difficulty and trickery of the actual College Board exam.

Key Concepts to Remember Before You Start:

  • Zero-Based Indexing: The first element of an array is always at index 0, and the last element is always at array.length - 1.
  • Default Initialization: When you use the new keyword, Java automatically fills the array. Primitive numbers default to 0, booleans default to false, and reference types (like Strings) default to null.
  • Fixed Size: Once a Java array is created, its size can never be changed.
  • The Out of Bounds Trap: Attempting to access an index that does not exist will immediately throw an ArrayIndexOutOfBoundsException.

Test your knowledge with the interactive quiz below. Be sure to read the explanations for any questions you miss!

AP CSA 6.1: Array Creation & Access

Question 1 of 10 | Score: 0
1. Consider the following code segment:
int[] numbers = new int[5];
numbers[0] = 4;
System.out.println(numbers[1]);
What is printed as a result of executing the code segment?
Correct Answer: B When an array of primitive integers is created using the new keyword, Java automatically initializes all elements to their default value, which is 0. Because numbers[0] was set to 4, the element at numbers[1] remains at its default initialization of 0. Distractor C is incorrect because only reference types default to null.
2. Consider the following code segment:
double[] prices = new double[4];
prices[4] = 10.50;
What is the result of executing this code segment?
Correct Answer: C In Java, arrays are zero-indexed. An array of size 4 has valid indices of 0, 1, 2, and 3. Attempting to access prices[4] goes past the end of the array, resulting in a runtime exception. Java arrays have fixed sizes and do not auto-expand.
3. Consider the following code segment:
String[] words = new String[3];
System.out.println(words[0].length());
What is the result of executing this code segment?
Correct Answer: D String is a reference type. When an array of reference types is created using new, all elements default to null. Therefore, words[0] contains null. Attempting to call a method like .length() on a null reference throws a NullPointerException.
4. Which of the following correctly initializes an array of integers with the values 1, 2, and 3?
Correct Answer: B Option B correctly uses an initializer list with curly braces. Option C is invalid because you cannot provide the size inside the brackets when also providing an initializer list. Option D places the size inside the declaration brackets on the left side, which is illegal in Java.
5. Consider the following code segment:
int[] list1 = {10, 20, 30};
int[] list2 = list1;
list2[0] = 99;
System.out.println(list1[0]);
What is printed as a result of executing the code segment?
Correct Answer: C This tests reference semantics. list1 holds a memory address pointing to the array. The statement int[] list2 = list1; does not copy the array; it copies the memory address. Both variables point to the exact same array. Changing list2[0] changes list1[0].
6. Consider the following code segment:
int[] vals = new int[10];
int lastElement = vals[vals.length];
What is the result of executing this code segment?
Correct Answer: C The length property returns the total number of elements, which is 10. Because arrays are zero-indexed, valid indices are 0 through 9. Accessing vals[10] causes an ArrayIndexOutOfBoundsException. The correct access is vals.length - 1.
7. Assume arr has been initialized with an odd number of integer elements. Which expression evaluates to the middle element?
Correct Answer: A In Java, integer division truncates the decimal. If arr.length is 5, the valid indices are 0, 1, 2, 3, 4 (middle is 2). 5 / 2 evaluates to 2, so arr[arr.length / 2] correctly accesses index 2.
8. Consider the following declaration:
boolean[] flags = new boolean[2];
What are the values of flags[0] and flags[1] immediately after this statement executes?
Correct Answer: B When an array of primitive boolean values is created using new, Java automatically initializes all elements to their default value, which is false.
9. Consider the following code segment:
int[] data = {5, 10, 15, 20};
int x = data[1];
data[1] = data[2];
data[2] = x;
What are the contents of the data array after this code executes?
Correct Answer: D This code implements a standard variable swap. First, x stores the value at index 1 (10). Then, the value at index 2 (15) overwrites index 1. Finally, the value stored in x (10) overwrites index 2.
10. Which of the following statements about array creation and access in Java is FALSE?
Correct Answer: C The expression arr.length returns the total number of elements in the array, not the highest valid index. Because arrays are zero-indexed, the highest valid index is always arr.length - 1.

Unit 6.1 Practice Complete!

0 / 10

Why Array Memory References Matter

Many students struggle with the difference between primitive variables and reference variables. As you saw in the practice questions above, an array variable doesn’t actually hold the list of numbers—it holds a memory address pointing to where that list lives in the computer’s RAM.

If you set array2 = array1, you haven’t created a second array. You have simply created a second remote control pointing to the exact same TV. This is a favorite trick on the AP CSA exam, so make sure you understand it completely.

Ready for the Next Step?

Now that you understand how to create arrays and access individual elements, it’s time to learn how to check every single element in the list automatically using loops.

Continue your AP CSA review by moving on to Topic 6.2: Array Traversal Practice, where we break down standard for loops, while loops, and common off-by-one errors.

← Back to Unit 6 Arrays Hub
Next: Topic 6.2 Array Traversal →

Primary Sidebar

Mr Chinmay

Chinmay Patel
Book a Demo Class

Phone & Whatsapp +919853166385
javatution@gmail.com

Recent Posts

  • Learn Java in One Day: 10-Hour 1-on-1 Crash Course | JavaTutorOnline
  • Constructor in Java and Overloaded Constructor Example Program
  • Important Interview Questions on Java Multithreading
  • React Spring Boot Web Services React Integration
  • Spring Boot RESTful Web Services Example
  • Top Spring MVC Interview Questions and Answers for Developers
  • Top Spring Core Interview Questions and Answers for Developers
  • Host Java Web Apps for Free on Mobile with Tomcat and Termux
  • How to Deploy Java Web Application on Aws EC2 with Elastic IP
  • Simple Jsp Servlet Jdbc User Registration using Tomcat Mysql and Eclipse

Additional Resources

  • AP Computer Science A Summer Prep
Copyright © 2026 JavaTutorOnline