---
title: "AP Computer Science A Unit 1 Practice Test"
description: "A timed AP Computer Science A Unit 1 (Using Objects and Methods) practice test in the AP format, drawn from 974 multiple-choice questions written for the unit. The standard version takes about 43 minutes."
canonical: "https://fiveable.me/ap-comp-sci-a/unit-test/1"
type: "unit-test"
subject: "AP Computer Science A"
unit: "Unit 1"
---

# AP Computer Science A Unit 1 Practice Test

## Overview

A timed AP Computer Science A Unit 1 (Using Objects and Methods) practice test in the AP format, drawn from 974 multiple-choice questions written for the unit. The standard version takes about 43 minutes.

## Test Format

- 20 Multiple Choice Questions (43 minutes)

## Practice Questions

### Question 1

Consider the following code segment.

```java
int a = 11;
int b = 4;
double x = (double) (a / b);
double y = (double) a / b;
System.out.println(x + " " + y);
```

What is printed as a result of executing this code segment?

- (A) 2.0 2.75
- (B) 2.75 2.75
- (C) 2.0 2.00
- (D) 2.75 2.0

**Answer: (A)** Tracing the order of operations for casting and division. The expression `(a / b)` performs integer division first, yielding `2`, which is then cast to `2.0`. The expression `(double) a` casts `11` to `11.0` first, resulting in floating-point division and `2.75`.

### Question 2

Consider the following code segment.

```java
double num = -5.8;
int a = (int) num;
int b = (int) (num - 0.5);
System.out.println(a + " " + b);
```

What is printed as a result of executing this code segment?

- (A) -5 -6
- (B) -6 -5
- (C) -6 -6
- (D) -5 -5

**Answer: (A)** Evaluating the truncation behavior of casting negative floating-point numbers. Casting `-5.8` directly to an integer truncates the decimal, resulting in `-5`. Subtracting `0.5` yields `-6.3`, which truncates to `-6`.

### Question 3

Consider the following code segment.

```java
int x = 10;
int y = 3;
x %= y;
y += x;
x *= y;
y /= 2;
System.out.println(x + " " + y);
```

What is printed as a result of executing this code segment?

- (A) 4 2
- (B) 4 1
- (C) 3 2
- (D) 3 1

**Answer: (A)** Tracing the sequential execution of compound assignment operators requires tracking the updated state of each variable. The variable `x` becomes 1 (10 % 3), then `y` becomes 4 (3 + 1). Next, `x` becomes 4 (1 * 4), and finally `y` becomes 2 (4 / 2), resulting in the output of 4 and 2.

### Question 4

Consider the following code segment.

```java
String s = "Val: ";
int n = 5;
n += 2;
s += n;
n *= 2;
s += n;
System.out.println(s);
```

What is printed as a result of executing this code segment?

- (A) "Val: 714"
- (B) "Val: 510"
- (C) "Val: 721"
- (D) "Val: 710"

**Answer: (A)** Evaluating compound assignment operators with mixed data types requires tracking both numeric operations and string concatenations. The integer `n` is updated to 7 and concatenated to form "Val: 7", then `n` is multiplied by 2 to become 14 and concatenated again to form "Val: 714".

### Question 5

Consider the following code segment.

```java
int val = 10;
int mod = 3;
val *= mod + 2;
val -= mod;
System.out.println(val);
```

What is printed as a result of executing this code segment?

- (A) 47
- (B) 29
- (C) 50
- (D) 32

**Answer: (A)** Applying the correct order of operations to compound assignment statements requires evaluating the entire right-hand expression first. The expression `mod + 2` evaluates to 5, so `val *= 5` updates `val` to 50. The final statement `val -= 3` reduces it to 47.

### Question 6

Consider the following code segment.

```java
int a = 2;
int b = 3;
String s1 = a + b + " sum";
String s2 = "sum " + a + b;
System.out.println(s1 + ", " + s2);
```

What is the result of attempting to compile and execute this code segment?

- (A) The code fails to compile due to a type mismatch.
- (B) The code compiles and prints out `5 sum, sum 5`.
- (C) The code compiles and prints out `5 sum, sum 23`.
- (D) The code compiles and prints out `23 sum, sum 23`.

**Answer: (C)** Applying Java's rules for operator precedence and String concatenation. In `s1`, the integer addition `a + b` evaluates first to 5, which is then concatenated with the String. In `s2`, the operation evaluates left-to-right, concatenating the String with `a` to form `"sum 2"`, which is then concatenated with `b` to form `"sum 23"`.

### Question 7

A programmer is designing a method to process loan applications. The method must accept the applicant's credit score (a whole number from 300 to 850) and their exact annual income, then return a value indicating whether the loan is approved. Which method signature is most appropriate?

- (A) `public boolean processLoan(int creditScore, double annualIncome)`
- (B) `public String processLoan(int creditScore, double annualIncome)`
- (C) `public boolean processLoan(double creditScore, double annualIncome)`
- (D) `public boolean processLoan(int creditScore, int applicantIncome)`

**Answer: (A)** Analyzing the required inputs and outputs for a financial calculation. The approval status requires a `boolean` return type, the credit score requires an `int`, and the exact income requires a `double`.

### Question 8

A programmer is designing a method to determine if a package exceeds a maximum weight limit. The method receives the package's exact weight in kilograms and the maximum allowed weight in kilograms. Which method signature is most appropriate?

- (A) `public boolean checkWeight(double packageWt, double maxWt)`
- (B) `public String checkWeight(double packageWt, double maxWt)`
- (C) `public boolean checkWeight(int packageWt, double maxWt)`
- (D) `public boolean checkWeight(double packageWt, int maxWt)`

**Answer: (A)** Evaluating data types for continuous measurements and logical outcomes. Exact weights require `double` parameters for decimal precision, and the yes/no outcome requires a `boolean` return type.

### Question 9

Consider the following class declaration.

```java
public class Logger {
    public void logError(String msg, int code) {
        /* missing code */
    }
}
```

A program calls `logError("Timeout", 404)` followed by `logError("Not found", 500)`. The intended output is:

```text
Error 404: Timeout
Error 500: Not found
```

Which of the following can replace `/* missing code */` so the method works as intended?

- (A) `System.out.print("Error " + code + ": "); System.out.println(msg);`
- (B) `System.out.println("Error " + code + ": "); System.out.print(msg);`
- (C) `System.out.print("Error " + code + ": "); System.out.print(msg);`
- (D) `System.out.println("Error " + code + ": "); System.out.println(msg);`

**Answer: (A)** Recognizing that `System.out.print` keeps the cursor on the same line, while `System.out.println` moves it to the next line after printing. To achieve the format `Error 404: Timeout` on a single line, the prefix must be printed with `print`, and the message with `println` to ensure subsequent logs start on a new line.

### Question 10

Consider the following class declaration.

```java
public class TimeFormatter {
    public void printDelimiter() {
        System.out.print(":");
    }
    
    public void formatTime(int h, int m, int s) {
        /* missing code */
    }
}
```

The `formatTime` method is intended to print the time in the format `h:m:s` and then move the cursor to a new line. Which of the following can replace `/* missing code */` so the method works as intended?

- (A) `System.out.print(h); printDelimiter(); System.out.print(m); printDelimiter(); System.out.print(s);`
- (B) `System.out.println(h); printDelimiter(); System.out.println(m); printDelimiter(); System.out.println(s);`
- (C) `System.out.print(h); printDelimiter(); System.out.print(m); printDelimiter(); System.out.println(s);`
- (D) `System.out.println(h); printDelimiter(); System.out.print(m); printDelimiter(); System.out.print(s);`

**Answer: (C)** Applying procedural abstraction to format output. To print `10:15:30` on a single line and then move to the next line, the hours, minutes, and delimiters must be printed using `print`, while the final seconds value must be printed using `println`.

## Review the Unit

- [1.1 Why Programming? Why Java?](/ap-comp-sci-a/unit-1/why-programming-why-java/study-guide/lVK6rmrBuug17i1Hna9z)
- [1.2 Variables and Primitive Data Types](/ap-comp-sci-a/unit-1/variables-and-primitive-data-types/study-guide/rezA6f3hJz84TKaY5Jjl)
- [1.3 Expressions and Assignment Statements](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr)
- [1.4 Assignment Statements and Input](/ap-comp-sci-a/unit-1/14-assignment-statement-input/study-guide/compoundassignment)
- [1.5 Casting and Ranges of Variables](/ap-comp-sci-a/unit-1/casting-and-ranges-of-variables/study-guide/kW3XXEIwJwVRXFx3ntdC)
- [1.6 Compound Assignment Operators](/ap-comp-sci-a/unit-1/compound-assignment-operators/study-guide/JiszeHqK8F9G6gszbgPL)
- [1.7 Application Program Interface (API) and Libraries](/ap-comp-sci-a/unit-1/application-program-interface-api-and-libraries/study-guide/sEpH1rg9TzREJwynSE9N)
- [1.8 Documentation With Comments](/ap-comp-sci-a/unit-1/documentation-with-comments/study-guide/scrDad77j4e5vwrFab5J)
- [1.9 Calling a Void Method With Parameters](/ap-comp-sci-a/unit-1/calling-void-method-with-parameters/study-guide/QVWxxGeVjbIbLpC10d1Y)
- [1.10 Calling a Non-Void Method](/ap-comp-sci-a/unit-1/calling-non-void-method/study-guide/gXkdn6sNrkDRHZsCVN1x)
- [1.11 Using the Math Class](/ap-comp-sci-a/unit-1/using-the-math-class/study-guide/6e652tzJOa5eE5mjPATE)
- [1.12 Objects: Instances of Classes](/ap-comp-sci-a/unit-1/objects-instances-of-classes/study-guide/EcpFHGcIKu6385hMohLe)
- [1.13 Creating and Storing Objects](/ap-comp-sci-a/unit-1/creating-and-storing-objects/study-guide/rUOTKl6Ih5noXJ0GtxJF)
- [1.14 Calling a Void Method](/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971)
- [1.15 String Methods](/ap-comp-sci-a/unit-1/string-methods/study-guide/SltCtk8JxBIgHcMfG6G4)

## Other Unit Tests

- [Unit 2: Selection and Iteration](/ap-comp-sci-a/unit-test/2)
- [Unit 3: Class Creation](/ap-comp-sci-a/unit-test/3)
- [Unit 4: Data Collections](/ap-comp-sci-a/unit-test/4)

## About This Document

Canonical Fiveable pages are available as Markdown at the same path plus `.md`.

- [llms.txt](https://fiveable.me/llms.txt): index of Fiveable's sections and URL patterns
- [llms-full.txt](https://fiveable.me/llms-full.txt): complete subject and unit listing
- [MCP server](https://fiveable.me/mcp): call Fiveable as tools instead of fetching pages (`https://fiveable.me/api/mcp`)
- [MCP server for AP teachers](https://fiveable.me/mcp/teachers): a teacher's classes, assignments and AP-rubric grading (`https://fiveable.me/api/mcp/teacher`)
