AP CSA 2025 Practice MCQ

AP CSA 2025 Practice Exam (42 Questions)

Timer: 90:00

Question 1

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

Question 2

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

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

Question 3

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

Question 4

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

Question 5

Which statement about String immutability is correct?

Question 6

Which expression evaluates to true?

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

Question 7

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

Question 8

What is the output of the following code?

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

Question 9

Which of the following is a valid method header?

Question 10

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

Question 11

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");
  

Question 12

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

Question 13

How many times does the loop run?

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

Question 14

What is printed?

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

Question 15

Which loop is guaranteed to run **at least once**?

Question 16

What is the output?

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

Question 17

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

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

Question 18

What does the code below print?

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

Question 19

What is printed?

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

Question 20

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);
  

Question 21

Which statement about constructors is correct?

Question 22

Which of the following best describes an instance variable?

Question 23

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());
  

Question 24

Which method is an example of a mutator?

Question 25

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

Question 26

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

Question 27

Which of the following is a correct constructor header?

Question 28

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());
  

Question 29

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

Question 30

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

Question 31

Which declaration correctly creates an array of 5 integers?

Question 32

What is printed?

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

Question 33

Which of the following correctly declares an ArrayList of Strings?

Question 34

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));
  

Question 35

Which of the following replaces the value list[2] in an ArrayList?

Question 36

What is printed?

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

Question 37

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

Question 38

What does list.size() return?

Question 39

What is printed?

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

Question 40

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

Question 41

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};
  

Question 42

Consider the following binary search scenario:

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

Which index will be checked first?

 

Contact form