AP Computer Science A AP Computer Science A Practice Test 2025
This is the official AP Computer Science A AP Computer Science A question paper for 2025, as set in the Model questions examination. It carries 80 full marks and a time allowance of 90 minutes, across 10 questions. On Kekkei you can attempt this AP Computer Science A past paper online with a timer, get instant AI feedback and step-by-step solutions, and track the topics where you lose marks — completely free. Whether you are revising for your AP Computer Science A AP Computer Science A exam or solving previous years' question papers, this 2025 paper is a great way to practise under real exam conditions.
| Level | AP Computer Science A |
|---|---|
| Subject | AP Computer Science A |
| Year | 2025 BS |
| Exam session | Model questions |
| Full marks | 80 |
| Time allowed | 90 minutes |
| Questions | 10, all with step-by-step solutions |
Multiple Choice
Select the best answer for each question.
Consider the following code segment.
int x = 17;
int y = 5;
double z = x / y;
System.out.println(z);
What is printed as a result of executing this code segment?
3.0
When both operands of the / operator are int, Java performs integer division, which truncates the decimal portion. So 17 / 5 evaluates to 3 (not 3.4). This integer result 3 is then assigned to the double variable z, which stores it as 3.0. Therefore, System.out.println(z) prints 3.0.
The correct answer is (b) 3.0.
Consider the following code segment.
String word = "PROGRAMMING";
int k = word.indexOf("GR");
String result = word.substring(k, k + 4);
System.out.println(result);
What is printed as a result of executing this code segment?
GRAM
The indexOf("GR") method searches for the first occurrence of "GR" in "PROGRAMMING". The string is indexed as: P(0) R(1) O(2) G(3) R(4) A(5) M(6) M(7) I(8) N(9) G(10). The substring "GR" starts at index 3 (G at index 3, R at index 4). So k = 3.
Then word.substring(3, 7) extracts characters from index 3 (inclusive) to index 7 (exclusive): G(3) R(4) A(5) M(6) = "GRAM".
The correct answer is (c) GRAM.
Consider the following code segment.
int a = 8;
int b = 15;
int c = 3;
if (a > b || b > 10 && c < 5) {
System.out.print("YES");
} else {
System.out.print("NO");
}
What is printed as a result of executing this code segment?
YES
In Java, the && operator has higher precedence than ||. So the expression is evaluated as:
a > b || (b > 10 && c < 5)
Step by step:
a > bevaluates to8 > 15which isfalseb > 10evaluates to15 > 10which istruec < 5evaluates to3 < 5which istrueb > 10 && c < 5evaluates totrue && truewhich istruefalse || trueevaluates totrue
Since the condition is true, the code prints "YES".
The correct answer is (a) YES.
Consider the following code segment.
int total = 0;
for (int i = 1; i <= 4; i++) {
total += i * i;
}
System.out.println(total);
What is printed as a result of executing this code segment?
30
The loop iterates with i taking values 1, 2, 3, and 4. In each iteration, i * i is added to total.
- Iteration 1:
i = 1,total = 0 + 1*1 = 1 - Iteration 2:
i = 2,total = 1 + 2*2 = 5 - Iteration 3:
i = 3,total = 5 + 3*3 = 14 - Iteration 4:
i = 4,total = 14 + 4*4 = 30
After the loop completes, total is 30.
The correct answer is (d) 30.
Consider the following code segment.
int[] nums = {4, 9, 2, 7, 5, 8};
int max = nums[0];
for (int i = 1; i < nums.length; i++) {
if (nums[i] > max) {
max = nums[i];
}
}
System.out.println(max);
What is printed as a result of executing this code segment?
9
The code finds the maximum value in the array {4, 9, 2, 7, 5, 8} by initializing max to nums[0] which is 4, then comparing each subsequent element.
i = 1:nums[1] = 9 > 4(true), somax = 9i = 2:nums[2] = 2 > 9(false),maxstays9i = 3:nums[3] = 7 > 9(false),maxstays9i = 4:nums[4] = 5 > 9(false),maxstays9i = 5:nums[5] = 8 > 9(false),maxstays9
The final value of max is 9.
The correct answer is (b) 9.
Consider the following code segment.
import java.util.ArrayList;
ArrayList<String> colors = new ArrayList<String>();
colors.add("Red");
colors.add("Blue");
colors.add("Green");
colors.add(1, "Yellow");
colors.remove(2);
System.out.println(colors.size() + " " + colors.get(2));
What is printed as a result of executing this code segment?
3 Green
Let's trace through the ArrayList operations step by step:
colors.add("Red")->["Red"]colors.add("Blue")->["Red", "Blue"]colors.add("Green")->["Red", "Blue", "Green"]colors.add(1, "Yellow")inserts"Yellow"at index 1, shifting everything after it ->["Red", "Yellow", "Blue", "Green"]colors.remove(2)removes the element at index 2, which is"Blue"->["Red", "Yellow", "Green"]
Now colors.size() returns 3 and colors.get(2) returns "Green" (the element at index 2).
So the output is 3 Green.
The correct answer is (c) 3 Green.
Consider the following code segment.
int[][] grid = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int sum = 0;
for (int col = 0; col < grid[0].length; col++) {
sum += grid[col][col];
}
System.out.println(sum);
What is printed as a result of executing this code segment?
15
The loop iterates through column indices col = 0, 1, 2. In each iteration, it accesses grid[col][col], which are the diagonal elements of the 3x3 matrix.
col = 0:grid[0][0] = 1col = 1:grid[1][1] = 5col = 2:grid[2][2] = 9
sum = 1 + 5 + 9 = 15
Note: Although the loop variable is named col, it is used as both the row and column index, so it traverses the main diagonal of the matrix.
The correct answer is (b) 15.
Consider the following class declarations.
public class Animal {
public String speak() {
return "...";
}
}
public class Dog extends Animal {
public String speak() {
return "Woof";
}
}
public class Puppy extends Dog {
public String speak() {
return "Yip";
}
}
What is printed by the following code segment?
Animal pet = new Puppy();
System.out.println(pet.speak());
Yip
This question tests the concept of polymorphism in Java. The variable pet has a compile-time type of Animal but a runtime type of Puppy.
In Java, when a method is called on an object, the runtime type (the actual object type) determines which version of the overridden method is executed. This is called dynamic method dispatch.
Since the actual object is a Puppy, and Puppy overrides the speak() method to return "Yip", the call pet.speak() invokes Puppy's version of speak(), which returns "Yip".
The correct answer is (d) Yip.
Consider the following recursive method.
public static int mystery(int n) {
if (n <= 1) {
return 1;
}
return n + mystery(n - 2);
}
What value is returned by the call mystery(7)?
16
We trace the recursive calls for mystery(7):
mystery(7):n = 7, not<= 1, returns7 + mystery(5)mystery(5):n = 5, not<= 1, returns5 + mystery(3)mystery(3):n = 3, not<= 1, returns3 + mystery(1)mystery(1):n = 1, base case reached, returns1
Now we unwind:
mystery(1) = 1mystery(3) = 3 + 1 = 4mystery(5) = 5 + 4 = 9mystery(7) = 7 + 9 = 16
The correct answer is (c) 16.
Consider the following sorted array and the binary search method below.
int[] data = {2, 5, 8, 12, 16, 23, 31, 42};
public static int binarySearch(int[] arr, int target) {
int low = 0;
int high = arr.length - 1;
int count = 0;
while (low <= high) {
int mid = (low + high) / 2;
count++;
if (arr[mid] == target) {
return count;
} else if (arr[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return -1;
}
What value is returned by the call binarySearch(data, 23)?
2
We trace the binary search for target = 23 in the sorted array {2, 5, 8, 12, 16, 23, 31, 42} (indices 0 through 7):
Iteration 1 (count = 1):
low = 0,high = 7,mid = (0 + 7) / 2 = 3arr[3] = 12, which is< 23, solow = 3 + 1 = 4
Iteration 2 (count = 2):
low = 4,high = 7,mid = (4 + 7) / 2 = 5arr[5] = 23, which== 23, so we returncount = 2
The binary search finds 23 after 2 comparisons.
The correct answer is (b) 2.
Frequently asked questions
- Where can I find the AP Computer Science A AP Computer Science A question paper 2025?
- The full AP Computer Science A AP Computer Science A 2025 (Model questions) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
- Does the AP Computer Science A 2025 paper come with solutions?
- Yes. Every question on this AP Computer Science A past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
- How many marks is the AP Computer Science A AP Computer Science A 2025 paper?
- The AP Computer Science A AP Computer Science A 2025 paper carries 80 full marks and is meant to be completed in 90 minutes, across 10 questions.
- Is practising this AP Computer Science A past paper free?
- Yes — reading and attempting this AP Computer Science A past paper on Kekkei is completely free.