Browse papers
LevelAP Computer Science A
SubjectAP Computer Science A
Year2025 BS
Exam sessionModel questions
Full marks80
Time allowed90 minutes
Questions10, all with step-by-step solutions
A

Multiple Choice

Select the best answer for each question.

10 questions·1 mark each
1Multiple choice1 mark

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?

  • a

    3.4

  • b

    3.0

  • c

    3

  • d

    4.0

Correct answer: b

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.

primitive-typesvariables
2Multiple choice1 mark

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?

  • a

    GRAP

  • b

    ROGR

  • c

    GRAM

  • d

    RAMM

Correct answer: c

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.

stringssubstringindexOf
3Multiple choice1 mark

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?

  • a

    YES

  • b

    NO

  • c

    YESNO

  • d

    A compile-time error occurs

Correct answer: a

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 > b evaluates to 8 > 15 which is false
  • b > 10 evaluates to 15 > 10 which is true
  • c < 5 evaluates to 3 < 5 which is true
  • b > 10 && c < 5 evaluates to true && true which is true
  • false || true evaluates to true

Since the condition is true, the code prints "YES".

The correct answer is (a) YES.

boolean-expressionsconditionals
4Multiple choice1 mark

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?

  • a

    10

  • b

    16

  • c

    20

  • d

    30

Correct answer: d

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.

iterationfor-looploop-tracing
5Multiple choice1 mark

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?

  • a

    8

  • b

    9

  • c

    4

  • d

    7

Correct answer: b

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), so max = 9
  • i = 2: nums[2] = 2 > 9 (false), max stays 9
  • i = 3: nums[3] = 7 > 9 (false), max stays 9
  • i = 4: nums[4] = 5 > 9 (false), max stays 9
  • i = 5: nums[5] = 8 > 9 (false), max stays 9

The final value of max is 9.

The correct answer is (b) 9.

arraystraversalfinding-max
6Multiple choice1 mark

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?

  • a

    3 Blue

  • b

    4 Green

  • c

    3 Green

  • d

    3 Yellow

Correct answer: c

3 Green

Let's trace through the ArrayList operations step by step:

  1. colors.add("Red") -> ["Red"]
  2. colors.add("Blue") -> ["Red", "Blue"]
  3. colors.add("Green") -> ["Red", "Blue", "Green"]
  4. colors.add(1, "Yellow") inserts "Yellow" at index 1, shifting everything after it -> ["Red", "Yellow", "Blue", "Green"]
  5. 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.

arraylistaddremovesize
7Multiple choice1 mark

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?

  • a

    12

  • b

    15

  • c

    6

  • d

    45

Correct answer: b

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] = 1
  • col = 1: grid[1][1] = 5
  • col = 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.

2d-arraysrow-column-traversal
8Multiple choice1 mark

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

    ...

  • b

    Woof

  • c

    A compile-time error occurs

  • d

    Yip

Correct answer: d

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.

inheritancepolymorphism
9Multiple choice1 mark

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

  • a

    12

  • b

    13

  • c

    16

  • d

    21

Correct answer: c

16

We trace the recursive calls for mystery(7):

  1. mystery(7): n = 7, not <= 1, returns 7 + mystery(5)
  2. mystery(5): n = 5, not <= 1, returns 5 + mystery(3)
  3. mystery(3): n = 3, not <= 1, returns 3 + mystery(1)
  4. mystery(1): n = 1, base case reached, returns 1

Now we unwind:

  • mystery(1) = 1
  • mystery(3) = 3 + 1 = 4
  • mystery(5) = 5 + 4 = 9
  • mystery(7) = 7 + 9 = 16

The correct answer is (c) 16.

recursiontracing-recursive-calls
10Multiple choice1 mark

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

  • a

    1

  • b

    2

  • c

    3

  • d

    5

Correct answer: b

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 = 3
  • arr[3] = 12, which is < 23, so low = 3 + 1 = 4

Iteration 2 (count = 2):

  • low = 4, high = 7, mid = (4 + 7) / 2 = 5
  • arr[5] = 23, which == 23, so we return count = 2

The binary search finds 23 after 2 comparisons.

The correct answer is (b) 2.

searchingbinary-search

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.