AP CSA 2025 Practice MCQ

AP CSA 2025 Practice Exam

42 Multiple-Choice Questions • 90 Minutes • 2025 Curriculum

⏱️ 90:00
0 of 42 answered

📋 Exam Instructions

  • This exam contains 42 multiple-choice questions covering all 4 AP CSA units.
  • You have 90 minutes to complete the exam (timer starts when you click "Start Exam").
  • Select one answer for each question.
  • You can change your answers before submitting.
  • Click "Submit Exam" when finished to see your score and explanations.
  • The exam will auto-submit when time runs out.

Question 1 Unit 1

Which of the following correctly declares and initializes a String variable?

✅ Correct Answer: B

In Java, Strings can be initialized using a string literal with double quotes: String s = "Hello";. Option A is missing parentheses, C has invalid syntax, and D uses C++ style constructor syntax not valid in Java.

Question 2 Unit 1

What is the value of result after the code below runs?

int a = 7;
int b = 2;
double result = (double) a / b;

✅ Correct Answer: B

Casting a to double before division makes this floating-point division: 7.0 / 2 = 3.5. Without the cast, integer division would give 3.

Question 3 Unit 1

What does the method call Math.abs(-12) return?

✅ Correct Answer: B

Math.abs() returns the absolute value of a number, which is always non-negative. The absolute value of -12 is 12.

Question 4 Unit 1

Given String s = "AP CSA"; what does s.substring(3) return?

✅ Correct Answer: C

substring(3) returns everything from index 3 to the end. In "AP CSA", index 0='A', 1='P', 2=' ', 3='C'. So substring(3) returns "CSA" starting at index 3, which includes the space: " CSA".

Question 5 Unit 1

Which statement about String immutability is correct?

✅ Correct Answer: D

Strings are immutable in Java, meaning they cannot be changed after creation. Methods like substring(), toUpperCase(), etc. return NEW String objects rather than modifying the original.

Question 6 Unit 1

Which expression evaluates to true?

String a = "cat";
String b = "cat";

✅ Correct Answer: C

.equals() compares content and returns true. Due to Java's String pool optimization, identical string literals also share the same reference, so == is also true here. However, always use .equals() for String comparison on the AP exam.

Question 7 Unit 1

Which of the following is not a primitive type in Java?

✅ Correct Answer: C

String is a reference type (a class), not a primitive. The primitive types in Java are: int, double, boolean, char, byte, short, long, and float. AP CSA focuses on int, double, and boolean.

Question 8 Unit 1

What is the output of the following code?

String w = "Java";
System.out.println(w.indexOf("a"));

✅ Correct Answer: B

indexOf() returns the index of the FIRST occurrence. In "Java": J=0, a=1, v=2, a=3. The first 'a' is at index 1.

Question 9 Unit 1

Which of the following is a valid method header?

✅ Correct Answer: A

A valid method header requires: access modifier (optional), return type, method name, and parameters with types. public void method(int x) follows this pattern correctly.

Question 10 Unit 1

What is returned by Math.max(3, Math.min(10, 6))?

✅ Correct Answer: B

Work inside out: Math.min(10, 6) = 6, then Math.max(3, 6) = 6.

Question 11 Unit 2

What does the following code print?

int n = 12;
if (n % 3 == 0 && n % 4 == 0)
    System.out.println("A");
else
    System.out.println("B");

✅ Correct Answer: A

12 % 3 == 0 is true (12 is divisible by 3) AND 12 % 4 == 0 is true (12 is divisible by 4). Since both conditions are true with &&, "A" is printed.

Question 12 Unit 2

Which Boolean expression is equivalent to !(x > 5 || y == 10)?

✅ Correct Answer: B

By De Morgan's Law: !(A || B) = !A && !B. So !(x > 5 || y == 10) = !(x > 5) && !(y == 10) = (x <= 5) && (y != 10).

Question 13 Unit 2

How many times does the loop run?

int count = 0;
for (int i = 3; i < 15; i += 3)
    count++;
System.out.println(count);

✅ Correct Answer: B

i takes values: 3, 6, 9, 12 (then 15 fails the condition). That's 4 iterations, so count = 4.

Question 14 Unit 2

What is printed?

int x = 5;
while (x < 20) {
    x += 7;
}
System.out.println(x);

✅ Correct Answer: C

x: 5 → 12 → 19 → 26. When x becomes 26, the condition (x < 20) is false, so the loop exits and prints 26.

Question 15 Unit 2

Which loop is guaranteed to run at least once?

✅ Correct Answer: C

A do-while loop checks its condition AFTER executing the body, so it always runs at least once. For and while loops check BEFORE, so they may not run at all. Note: do-while is not on the AP CSA exam but is good to know.

Question 16 Unit 2

What is the output?

for (int i = 10; i > 0; i -= 4) {
    System.out.print(i + " ");
}

✅ Correct Answer: A

i: 10 (print), 6 (print), 2 (print), -2 (fails i > 0). Output: "10 6 2 "

Question 17 Unit 2

Which condition will cause the loop to execute exactly 7 times?

int i = 3;
while ( ______ ) {
    i++;
}

✅ Correct Answer: A

Starting at i=3, we need 7 iterations to reach i=10. With i <= 9: i goes 3,4,5,6,7,8,9 (7 times), then i=10 fails the condition. Options B and C give 7 and 8 iterations respectively.

Question 18 Unit 2

What does the code below print?

int sum = 0;
for (int k = 1; k <= 4; k++) {
    sum += k * 2;
}
System.out.println(sum);

✅ Correct Answer: C

k=1: sum += 2 (sum=2); k=2: sum += 4 (sum=6); k=3: sum += 6 (sum=12); k=4: sum += 8 (sum=20).

Question 19 Unit 2

What is printed?

int x = 0;
int y = 3;
if (x != 0 && y / x > 1)
    System.out.println("A");
else
    System.out.println("B");

✅ Correct Answer: B

Short-circuit evaluation! Since x != 0 is false, Java doesn't evaluate y / x (which would cause division by zero). The entire condition is false, so "B" prints.

Question 20 Unit 2

What is printed by the following nested loop?

int c = 0;
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 2; j++) {
        c++;
    }
}
System.out.println(c);

✅ Correct Answer: D

Outer loop runs 3 times (i=0,1,2). Inner loop runs 2 times each (j=0,1). Total: 3 × 2 = 6 iterations.

Question 21 Unit 3

Which statement about constructors is correct?

✅ Correct Answer: B

Constructors are called automatically when you use new to create an object. They have no return type (not even void), can take parameters, and a class can have multiple constructors (overloading).

Question 22 Unit 3

Which of the following best describes an instance variable?

✅ Correct Answer: C

Instance variables belong to specific objects—each object has its own copy. Variables inside methods are local variables. Static variables are shared by all objects.

Question 23 Unit 3

Given the class below, what is printed?

public class Counter {
    private int value;
    
    public Counter(int start) {
        value = start;
    }
    
    public void increment() {
        value++;
    }
    
    public int getValue() {
        return value;
    }
}

Counter c = new Counter(7);
c.increment();
System.out.println(c.getValue());

✅ Correct Answer: C

Constructor sets value to 7. increment() increases it to 8. getValue() returns 8.

Question 24 Unit 3

Which method is an example of a mutator?

✅ Correct Answer: C

Mutators (setters) modify instance variables. They typically have void return type and take a parameter. Accessors (getters) return values without modifying state.

Question 25 Unit 3

What is true about a class with two methods that have the same name but different parameters?

✅ Correct Answer: B

Method overloading allows multiple methods with the same name but different parameter lists. Java distinguishes them by their signatures (name + parameters).

Question 26 Unit 3

When this.x is used inside a class method, what does it refer to?

✅ Correct Answer: D

this refers to the current object. this.x explicitly refers to the instance variable x of the current object, often used to distinguish from a parameter with the same name.

Question 27 Unit 3

Which of the following is a correct constructor header?

✅ Correct Answer: B

Constructors have NO return type (not even void). Option A has void, making it a regular method. B is correct: access modifier + class name + parameters.

Question 28 Unit 3

Consider the class definition:

public class Light {
    private boolean on;
    
    public Light(boolean o) {
        on = o;
    }
    
    public void toggle() {
        on = !on;
    }
    
    public boolean isOn() {
        return on;
    }
}

Light lamp = new Light(true);
lamp.toggle();
System.out.println(lamp.isOn());

✅ Correct Answer: B

Constructor sets on = true. toggle() flips it: on = !true = false. isOn() returns false.

Question 29 Unit 3

Which keyword is used to prevent other classes from directly modifying instance variables?

✅ Correct Answer: B

private restricts access to within the class only. This is the foundation of encapsulation—hiding implementation details and providing controlled access through methods.

Question 30 Unit 3

Which of the following is not a reason to use accessor (getter) methods?

✅ Correct Answer: B

Accessors (getters) only READ values—they don't allow direct modification. That's what mutators (setters) do, with controlled access. B describes bypassing encapsulation, which is bad practice.

Question 31 Unit 4

Which declaration correctly creates an array of 5 integers?

✅ Correct Answer: C

Correct syntax: type[] name = new type[size];. Option D creates an array with one element (the value 5), not 5 elements.

Question 32 Unit 4

What is printed?

int[] a = {2, 4, 6, 8};
System.out.println(a[2]);

✅ Correct Answer: C

Arrays are 0-indexed: a[0]=2, a[1]=4, a[2]=6, a[3]=8. So a[2] is 6.

Question 33 Unit 4

Which of the following correctly declares an ArrayList of Strings?

✅ Correct Answer: D

Both B and C are valid. C uses the diamond operator (<>) which infers the type from the left side. A works but is not type-safe (raw type).

Question 34 Unit 4

What is printed by the following?

ArrayList list = new ArrayList<>();
list.add(3);
list.add(7);
list.add(1);
System.out.println(list.get(1));

✅ Correct Answer: C

After adds: list = [3, 7, 1]. Index 0=3, index 1=7, index 2=1. get(1) returns 7.

Question 35 Unit 4

Which of the following replaces the value at index 2 in an ArrayList?

✅ Correct Answer: B

ArrayList uses methods, not bracket notation. set(index, value) replaces the element at the given index. Arrays use brackets; ArrayLists use methods.

Question 36 Unit 4

What is printed?

int[] nums = {10, 20, 30, 40};
for (int i = 0; i < nums.length; i += 2)
    System.out.print(nums[i] + " ");

✅ Correct Answer: B

i starts at 0, increments by 2: i=0 (print 10), i=2 (print 30), i=4 (fails condition). Output: "10 30 "

Question 37 Unit 4

What is the index of the last element in an array with length n?

✅ Correct Answer: B

Arrays are 0-indexed, so indices range from 0 to n-1. The last element is always at index n-1. Accessing index n causes ArrayIndexOutOfBoundsException.

Question 38 Unit 4

What does list.size() return?

✅ Correct Answer: B

size() returns the current number of elements stored, not capacity or max size. For arrays, use .length; for ArrayLists, use .size().

Question 39 Unit 4

What is printed?

int[] arr = {1, 3, 5, 7};
int sum = 0;
for (int v : arr)
    sum += v;
System.out.println(sum);

✅ Correct Answer: C

Enhanced for loop adds each element: 1 + 3 + 5 + 7 = 16.

Question 40 Unit 4

What happens when list.get(10) is called on an ArrayList with only 5 elements?

✅ Correct Answer: C

Accessing an index outside the valid range (0 to size-1) throws IndexOutOfBoundsException at runtime. With 5 elements, valid indices are 0-4.

Question 41 Unit 4

A linear search is being used on the array below. How many comparisons are needed to find the value 18?

int[] nums = {4, 9, 12, 18, 22, 25};

✅ Correct Answer: D

Linear search checks elements one by one from the start: compare with 4 (no), 9 (no), 12 (no), 18 (yes!). That's 4 comparisons.

Question 42 Unit 4

Consider the following binary search scenario:

int[] a = {2, 5, 7, 11, 14, 20, 25};
Searching for: 14

Which index will be checked first?

✅ Correct Answer: C

Binary search starts at the middle index. Array length = 7, so middle = (0 + 6) / 2 = 3. Index 3 contains 11, which is checked first.

0 of 42 questions answered

📊 Exam Results

0%

0 out of 42 correct

0
Correct
0
Incorrect
0
Unanswered
0:00
Time Used
Practice FRQs →

Contact form