• 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: Mock Exam MCQs

Home » AP CSA MCQ » Unit 6

AP CSA Unit 6 Arrays: Mock Exam

📚 Comprehensive Test ⏱️ 25 Min Practice ✅ Updated for 2027 Exam

You have reached the final challenge of Unit 6. Mastering 1D Arrays is the bridge between basic Java syntax and advanced object-oriented data structures. If you can confidently navigate arrays, you are well on your way to earning a 5 on the AP Computer Science A exam.

This Unit 6 Mock Exam contains 15 exam-level questions that mix all the concepts we have covered: array creation, memory references, standard traversals, enhanced for-loops, and shifting algorithms.

Tips for the Mock Exam:

  • Trace Everything: Do not rely on mental math. Write down the array indices and update their values as you trace through the loops.
  • Check the Bounds: The most common distractor on the AP exam is the ArrayIndexOutOfBoundsException. Always verify the loop’s starting index and its termination condition.
  • Remember References: If two array variables point to the same array, changing one changes the other.

Treat this like the real test. Grab a piece of scratch paper, eliminate the obvious wrong answers, and begin!

Unit 6 Mock Exam

Question 1 of 15 | Score: 0
1. Consider the following code segment:
int[] arr = new int[5];
arr[0] = 3;
arr[2] = 7;
System.out.println(arr[4]);
What is printed as a result of executing the code segment?
Correct Answer: A When an integer array is initialized, all elements default to 0. Since `arr[4]` was never explicitly assigned a value, it remains 0. Index 4 is the final valid index in an array of size 5, so no bounds exception occurs.
2. Consider the following code segment:
int[] list1 = {10, 20, 30};
int[] list2 = list1;
list2[1] = 99;
System.out.println(list1[1] + list2[1]);
What is printed as a result of executing the code segment?
Correct Answer: C `list1` and `list2` are reference variables pointing to the exact same array in memory. Changing `list2[1]` to 99 also changes `list1[1]` to 99. Therefore, `99 + 99 = 198`.
3. Which of the following conditions is most likely to cause an ArrayIndexOutOfBoundsException in a standard for-loop traversing an array named data?
Correct Answer: C Arrays are zero-indexed. The last valid index is always `data.length – 1`. The condition `<= data.length` allows the loop to run when `i` equals the length of the array, attempting to access an index that does not exist.
4. Consider the following code segment:
int[] vals = {5, 10, 15, 20};
for (int i = vals.length – 1; i >= 0; i–) {
    System.out.print(vals[i] + ” “);
}
What is the output of this code?
Correct Answer: B This is a flawless backward traversal. `i` starts at 3 (the last index) and correctly decrements down to and including 0 (`>= 0`). It prints the array in reverse order.
5. Consider the following code segment:
int[] nums = {1, 2, 3, 4};
for (int n : nums) {
    n = n * 2;
}
System.out.println(nums[0]);
What is printed as a result of executing the code segment?
Correct Answer: B Enhanced for-loops create a read-only copy of primitive elements. Modifying `n` inside the loop does not affect the original `nums` array. The array remains {1, 2, 3, 4}, so `nums[0]` is still 1.
6. Consider the following code segment intended to shift elements one position to the left:
int[] arr = {10, 20, 30, 40};
int temp = arr[0];
for (int i = 0; i < arr.length – 1; i++) {
    arr[i] = arr[i + 1];
}
arr[arr.length – 1] = temp;
What are the contents of the array after execution?
Correct Answer: B This correctly implements a full left shift. `temp` stores the 10. The loop shifts 20, 30, and 40 left. At the end of the loop, the array is {20, 30, 40, 40}. Finally, `temp` (10) is placed at the last index, resulting in {20, 30, 40, 10}.
7. Consider the following code segment:
int[] arr = {4, 7, 2, 8, 1};
int count = 0;
for (int i = 1; i < arr.length – 1; i++) {
    if (arr[i] > arr[i – 1] && arr[i] > arr[i + 1]) {
        count++;
    }
}
System.out.println(count);
What is printed as a result of executing the code segment?
Correct Answer: C This algorithm counts “peaks”—elements that are strictly greater than both their left and right neighbors. It starts at index 1 and stops at `length – 2` to avoid bounds errors. The peaks are 7 (greater than 4 and 2) and 8 (greater than 2 and 1). Thus, `count` is 2.
8. Which of the following is true regarding String arrays?
Correct Answer: A Strings are Objects (reference types). All arrays of reference types default to `null`. Option B is false. Option C is false (you should use `.equals()`). Option D is false because arrays use the `length` property, not the `length()` method.
9. Consider the following code segment:
int[] arr = {1, 2, 3, 4, 5};
for (int i = 0; i < arr.length; i += 2) {
    arr[i] = 0;
}
What are the contents of the array after execution?
Correct Answer: A The loop starts at index 0 and jumps by 2 (`i += 2`). It changes the values at indices 0, 2, and 4 to zero. The elements at indices 1 and 3 are untouched.
10. Consider the following code segment:
boolean[] flags = new boolean[3];
flags[1] = true;
boolean result = flags[0] || flags[1];
System.out.println(result);
What is printed as a result of executing the code segment?
Correct Answer: A A newly created boolean array defaults to `false`. Therefore `flags[0]` is `false` and `flags[1]` is manually set to `true`. The expression `false || true` (OR operator) evaluates to `true`.
11. Consider the following method designed to reverse an array:
public void reverse(int[] arr) {
    for (int i = 0; i < arr.length / 2; i++) {
        arr[i] = arr[arr.length – 1 – i];
        arr[arr.length – 1 – i] = arr[i];
    }
}
Why does this method fail to reverse the array correctly?
Correct Answer: C Because there is no `temp` variable, line 3 immediately overwrites the data at index `i`. On line 4, when trying to complete the swap, the original value at index `i` is already lost. It will end up mirroring the right side of the array onto the left side.
12. Consider the following code segment:
String[] words = {“A”, “B”, “C”};
for (int i = 0; i < words.length; i++) {
    words[i] += “!”;
}
System.out.println(words[1]);
What is printed as a result of executing the code segment?
Correct Answer: B This is a standard for-loop, NOT an enhanced for-loop. Therefore, accessing and updating `words[i]` successfully modifies the original array. Each string has an exclamation point appended. `words[1]` prints “B!”.
13. Consider the following code segment:
int[] arr = {1, 2, 3, 4, 5};
int x = 0;
for (int num : arr) {
    if (num % 2 != 0) {
        x += num;
    }
}
System.out.println(x);
What is printed as a result of executing the code segment?
Correct Answer: B The condition `num % 2 != 0` checks if a number is odd. The loop traverses the array and adds only the odd numbers (1, 3, and 5) to the accumulator variable `x`. The final sum is 9.
14. Consider the following code segment:
int[] nums = {-5, -10, -3, -8};
int max = 0;
for (int i = 0; i < nums.length; i++) {
    if (nums[i] > max) {
        max = nums[i];
    }
}
System.out.println(max);
What is printed as a result of executing the code segment?
Correct Answer: C This is a flawed max algorithm. Because `max` is initialized to 0, and all the numbers in the array are negative, the condition `nums[i] > max` is never true. The variable `max` remains at 0 and is printed, even though 0 is not in the array.
15. Consider the following code segment:
int[] arr = {1, 1, 1, 1, 1};
for (int i = 1; i < arr.length; i++) {
    arr[i] = arr[i] + arr[i – 1];
}
System.out.println(arr[arr.length – 1]);
What is printed as a result of executing the code segment?
Correct Answer: C This creates a running cumulative sum. Loop tracing: i=1: arr[1] = 1 + arr[0] (1) = 2. i=2: arr[2] = 1 + arr[1] (2) = 3. i=3: arr[3] = 1 + arr[2] (3) = 4. i=4: arr[4] = 1 + arr[3] (4) = 5. The last index (4) contains the value 5.

Unit 6 Exam Complete!

0 / 15

Moving Forward: Arrays vs. ArrayLists

Congratulations on completing the Unit 6 Arrays curriculum! If you can confidently navigate through indices, avoid bounds exceptions, and utilize both standard and enhanced for-loops, you have mastered one of the most important concepts in computer science.

However, standard 1D arrays have one massive limitation: their size is fixed. If you create an array to hold 5 items, you can never add a 6th. In the real world, data constantly grows and shrinks.

To solve this problem, Java offers a dynamic data structure that can expand automatically. Prepare to level up your programming skills by moving into ArrayLists, where we explore how to build flexible, resizable lists!

Need to Review Before Testing?

Review our targeted practice modules to brush up on specific concepts:

  • Return to Unit 6 Arrays Practice Hub
  • Topic 6.1 – Array Creation & Access
  • Topic 6.2 – Traversing Arrays
  • Topic 6.3 – Enhanced For-Loops
  • Topic 6.4 – Standard Algorithms

Want to Boost Your AP CSA Score to a 5?

Get expert, 1-on-1 online instruction tailored to your exact weak spots with a senior software engineer.

Explore AP CSA 1-on-1 Tutoring →

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