• 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
      • Booleans
      • Iteration
      • Arrays
      • View all Units
  • Courses
  • Tutorials
    • Java
    • Servlets
    • Struts
    • Spring
    • Webservice
  • FAQ
  • Testimonials
  • Blog
  • CONTACT US

AP CSA Unit 4.3 MCQ Practice: Array Creation and Access

Home » AP CSA MCQ » Unit 4: Data Collections

AP CSA Unit 4.3 MCQ Practice: Array Creation & Access

📚 Topic 4.3 ⏱️ 10 Min Practice ✅ Current AP CSA Framework

Mastering arrays is one of the most critical steps in scoring a 5 on the AP Computer Science A exam. Unit 4: Data Collections includes arrays as an important data abstraction. In Topic 4.3, you learn how one-dimensional arrays are created, initialized, and accessed using indexes.

In this interactive practice set, we cover Topic 4.3: Array Creation and Access. These 10 multiple-choice questions focus on array creation, initialization, length, indexing, and access.

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 4.3: 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 stores a reference to an array object. The statement int[] list2 = list1; does not create a second array; both variables refer to the same array object. Changing list2[0] therefore also 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 4.3 Practice Complete!

0 / 10

Understanding Array References

Many students struggle with the difference between primitive variables and reference variables. An array variable stores a reference to an array object. If two array variables refer to the same array object, changing an element through either variable changes that same array object.

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 4.4: Array Traversal Practice , where you will practice traversing arrays with loops and avoiding common off-by-one errors.

← Back to Unit 4: Data Collections
Next: Topic 4.4 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: Examples, Types & Constructor Overloading
  • 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