Unit 1 Practice Exam: Objects and Methods | AP CSA
AP CSA Practice Exam
Unit 1 Practice Exam: Objects and Methods
50 Questions • 2025-2026 Curriculum • Unit 1: Objects, Strings, Math, Wrappers (15-25% of exam)
0Correct
0Incorrect
0/50Progress
Exam Overview: Unit 1 covers 15-25% of the AP CSA exam. The full AP CSA exam is 42 MCQ (55%) plus 4 FRQ (45%), delivered fully digitally via Bluebook. Topics in this set: object creation and references, String methods, type conversion, wrapper classes, and the Math class. Formats: Error Detection, I/II/III multi-select, and Predict the Output — all at AP exam difficulty.
Section 1: Object Creation and References
Error Detection
Question 1
Consider the following code segment. What will happen when this code is executed?
String data = null; int len = data.length(); System.out.println(len);
I/II/III Format
Question 2
Consider the following code segment:
String a = "Code";
String b = "Code";
String c = new String("Code");
String d = a;
Which of the following statements evaluate to
I.
II.
III.
true?I.
a == bII.
a == cIII.
a == d
Error Detection
Question 3
A student wrote the following code intending to concatenate " Data" onto the variable and print the result. What will actually be printed?
String a = "Test";
String b = a.toUpperCase();
a.concat(" Data");
System.out.println(a);
Predict the Output
Question 4
Before looking at the choices, trace the code and predict the output.
String m = "Java"; String n = m; m = "Python"; System.out.println(m + " " + n);
Error Detection
Question 5
Which of the following is NOT a valid way to declare and initialize a Scanner object to read from the console?
I/II/III Format
Question 6
Consider the following declarations:
Integer num1 = 100; Integer num2 = 100; Integer num3 = 1000; Integer num4 = 1000;
Which of the following evaluate to
I.
II.
III.
true?I.
num1 == num2II.
num3 == num4III.
num1.equals(num2)
Predict the Output
Question 7
Before looking at the choices, predict what the following code segment prints.
String val = ""; System.out.println(val == null); System.out.println(val.length());
Error Detection
Question 8
A student is debugging code and finds the following segment. What does it print?
String s1 = "AP"; String s2 = "ap"; boolean check = s1.equalsIgnoreCase(s2) && (s1 == s2); System.out.println(check);
Predict the Output
Question 9
Before looking at the choices, trace the code and predict the output.
String p = new String("Test");
String q = new String("Test");
String r = p;
System.out.println(p.equals(q) + " " + (p == r));
I/II/III Format
Question 10
Consider the following code segment:
Object ref; // Line inserted here System.out.println(ref);
Which of the following lines, when inserted, allow the code to compile AND run without an exception?
I.
II.
III.
I.
ref = "Hello";II.
ref = Integer.valueOf(42);III.
ref = null;
Predict the Output
Question 11
Before looking at the choices, determine the output of the following code.
int count = 0;
String s = "banana";
for (int i = 0; i < s.length(); i++) {
if (s.substring(i, i+1).equals("a")) count++;
}
System.out.println(count);
Error Detection
Question 12
A student intends to swap the values of two Integer objects. What actually happens when this code runs?
public static void swap(Integer a, Integer b) {
Integer temp = a;
a = b;
b = temp;
}
// In main:
Integer x = 10, y = 20;
swap(x, y);
System.out.println(x + " " + y);
Section 2: String Methods
Predict the Output
Question 13
Before looking at the choices, trace the method calls and predict the output.
String text = "examination"; System.out.println(text.substring(2, 6));
Error Detection
Question 14
What happens when the following code executes?
String word = "Java"; String ch = word.substring(4, 5);
I/II/III Format
Question 15
Consider
String str = "Hello World". Which of the following expressions evaluate to true?
I.
II.
III.
str.indexOf("o") == str.lastIndexOf("o")II.
str.substring(6).equals("World")III.
str.length() == 11
Error Detection
Question 16
A student wants to print the FIRST and LAST occurrences of "ss" in a string. Identify the bug.
String phrase = "Mississippi";
int pos1 = phrase.lastIndexOf("ss");
int pos2 = phrase.indexOf("ss");
System.out.println("First: " + pos1 + ", Last: " + pos2);
Predict the Output
Question 17
Before looking at the choices, trace the method chain and predict the output.
String data = "Computer Science"; String result = data.substring(0, 8).toLowerCase(); System.out.println(result);
Predict the Output
Question 18
Before looking at the choices, predict the output of the following code.
String input = " spaces ";
System.out.println("[" + input + "]");
System.out.println("[" + input.substring(2, 8) + "]");
I/II/III Format
Question 19
Consider the following code segment:
String original = "apple"; String modified = original.toUpperCase();
Which of the following statements are
I.
II.
III.
true after this code executes?I.
original.equals("apple")II.
modified.equals("APPLE")III.
original == modified
Error Detection
Question 20
A student expects the following code to print
PrograXXing. What will actually be printed?String s = "Programming";
String t = s.replace("m", "X");
System.out.println(s);
Predict the Output
Question 21
Before looking at the choices, predict the output of the following code.
String s = "12345"; System.out.println(s.substring(1, 4).length());
I/II/III Format
Question 22
Consider
String data = "ABCABC". Which of the following statements are true?
I.
II.
III.
data.indexOf("X") == -1II.
data.indexOf("ABC") == 0III.
data.lastIndexOf("ABC") == 3
Error Detection
Question 23
A student uses == to compare Strings. What does this code print?
String text = "Testing";
if (text.compareTo("Test") == 0) {
System.out.println("Equal");
} else if (text == "Test") {
System.out.println("Same reference");
} else {
System.out.println("Not equal");
}
Predict the Output
Question 24
Before looking at the choices, predict the output of the following code.
String s = "abcdefg";
System.out.println(s.substring(s.indexOf("d")));
Section 3: String Concatenation and Type Conversion
Predict the Output
Question 25
Before looking at the choices, predict the output. Pay close attention to operator precedence.
int a = 4;
int b = 2;
System.out.println("Result: " + a + b * 2);
Predict the Output
Question 26
Before looking at the choices, predict the output of the following code.
System.out.println(3 + 4 + "5" + 6 + 7);
Error Detection
Question 27
Which of the following will cause a compile-time error?
Predict the Output
Question 28
Before looking at the choices, predict the output of the following code.
int value = 17; int divisor = 5; System.out.println(value / divisor + " R " + value % divisor);
Error Detection
Question 29
A student runs the following code expecting it to print
12. What will actually happen?String input = "12.5"; int value = Integer.parseInt(input); System.out.println(value);
Predict the Output
Question 30
Before looking at the choices, determine the value of
result.String input = "42"; int num = Integer.parseInt(input); double result = num / 4.0;
I/II/III Format
Question 31
Consider the following expressions where
x = 10 and y = 3. Which expressions evaluate to 3?
I.
II.
III.
x / yII.
x % yIII.
(int)(x / (double) y)
Predict the Output
Question 32
Before looking at the choices, predict the output of the following code.
String s = "25"; String t = "5"; System.out.println(s + t + " vs " + (Integer.parseInt(s) + Integer.parseInt(t)));
Section 4: Wrapper Classes and Autoboxing
Predict the Output
Question 33
Before looking at the choices, trace the code and predict the output.
Integer val = 50; int primitive = val; val = val + 10; System.out.println(primitive + " " + val);
Error Detection
Question 34
A student writes the following code expecting it to print
0. What actually happens?Integer y = null; int z = y; System.out.println(z);
I/II/III Format
Question 35
Which of the following code segments compile WITHOUT a compile-time error?
I.
II.
III.
Integer x = 5; x++;II.
Integer y = null; int z = y;III.
int a = 10; Integer b = a;
Error Detection
Question 36
A student writes the following code expecting
true. What will actually be printed?Integer a = 150; Integer b = 150; System.out.println(a == b);
Predict the Output
Question 37
Before looking at the choices, predict the output of the following code.
System.out.println(Integer.MAX_VALUE + 1);
Predict the Output
Question 38
Before looking at the choices, predict the output of the following code.
Double d = 3.14159; System.out.println(d.intValue() + " " + Math.round(d));
Section 5: Math Class
Error Detection
Question 39
A student wants to generate a random integer between 5 and 15 INCLUSIVE. Which code correctly accomplishes this?
I/II/III Format
Question 40
Which of the following expressions ALWAYS return a value of type
double?
I.
II.
III.
Math.pow(2, 3)II.
Math.sqrt(16)III.
Math.abs(-5)
Predict the Output
Question 41
Before looking at the choices, predict what values
n can hold after the following code executes.int n = (int)(Math.random() * 6);
Error Detection
Question 42
A student wants code that produces values from the set {0, 5, 10, 15}. Does the following code work as intended?
int mystery = (int)(Math.random() * 4) * 5;
Predict the Output
Question 43
Before looking at the choices, predict the output of the following code.
System.out.println(Math.min(Math.max(3, 7), 5));
Error Detection
Question 44
Which statement about
Math.random() is NOT correct?
I/II/III Format
Question 45
Which of the following expressions are ALWAYS true regardless of the value of
x?
I.
II.
III.
Math.abs(x) >= 0II.
Math.abs(x) == xIII.
Math.abs(-x) == Math.abs(x)
Predict the Output
Question 46
Before looking at the choices, trace the code and predict the output.
double d = -3.7; System.out.println(Math.abs((int) d) + " " + (int) Math.abs(d));
Predict the Output
Question 47
Before looking at the choices, predict the output of the following code.
System.out.println(Math.sqrt(Math.pow(3, 2) + Math.pow(4, 2)));
I/II/III Format
Question 48
Consider
int a = -8; int b = 3;. Which of the following expressions evaluate to 2?
I.
II.
III.
Math.abs(a % b)II.
a % Math.abs(b)III.
Math.abs(a) % b
Error Detection
Question 49
A student wants to generate a random number from 1 to 10 INCLUSIVE. Which implementation is INCORRECT?
Predict the Output
Question 50
Before looking at the choices, predict the output of the following code.
System.out.println((int) Math.pow(2, 10));
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Typically responds within 24 hours
✓
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
✉
Email
tanner@apcsexamprep.com
📚
Courses
AP CSA, CSP, & Cybersecurity
⏱
Response Time
Within 24 hours
Prefer email? Reach me directly at tanner@apcsexamprep.com