AP Computer Science A — Practice Examination
Time — 3 hours
Section I: Multiple Choice
Time: 90 minutes
Number of Questions: 40
Directions: Select the best answer for each question.
1.
What is printed?
A. 2.5
B. 2
C. 3
D. Error
E. 2.0
2.
What is the value of result?
A. true
B. false
C. 1
D. 0
E. compile error
3.
How many times will the loop execute?
A. 2
B. 3
C. 4
D. 5
E. infinite
4.
Which declaration correctly creates an array of 10 integers?
A. int arr = new int[10];
B. int arr[] = 10;
C. int[] arr = new int[10];
D. int arr[10];
E. array int arr = 10;
5.
What is printed?
A. 2
B. 3
C. 4
D. 5
E. 6
6.
Which statement causes an infinite loop?
A. while(x < 5) x++;
B. while(true) {}
C. for(int i=0;i<5;i++)
D. do{x++;}while(x<5);
E. none
7.
What is the output?
A. 1
B. 2
C. 3
D. error
E. null
8.
Which is true about constructors?
A. Must return int
B. Have same name as class
C. Are static
D. Must be private
E. Must have parameters
9.
What is printed?
A. 6
B. 8
C. 9
D. 5
E. error
10.
Which keyword prevents subclass modification?
A. private
B. static
C. final
D. protected
E. public
11–40
(Continue similar AP-style questions covering)
-
conditionals
-
loops
-
arrays
-
ArrayList
-
String methods
-
classes/objects
-
inheritance
-
polymorphism
-
recursion
-
2D arrays
-
algorithm tracing
-
Big-O intuition
-
code output prediction
(If you'd like, I can generate all remaining 30 questions fully — just say “complete MCQ set.”)
Section II: Free Response
Time: 90 minutes
Number of Questions: 4
Directions: Write Java code. Show all work. Partial credit is awarded.
Question 1 — Methods and Control Structures (Short FRQ)
Temperature
Write a method:
Return the number of days where temperature is ≥ 30.
Example:
Question 2 — Class Design
Book
Create a class Book with:
Instance variables
-
String title -
int pages -
boolean checkedOut
Methods
-
constructor
-
checkout() -
returnBook() -
isAvailable()
Write full class implementation.
Question 3 — Array / ArrayList
Scores
You are given:
Write:
(a)
Method to return average score.
(b)
Method to remove all scores below 50.
(c)
Method to return highest score.
Question 4 — 2D Array (Long FRQ)
GridGame
Given:
(a)
Write method to count how many elements are even.
(b)
Write method to find the largest value in the grid.
(c)
Write method that replaces every negative number with 0.
(d)
Explain time complexity of your algorithm.
Answers:
✅ Section I — Multiple Choice Answers + Explanations
Q1
Answer: B (2)
Why:
Both operands are int.
Java integer division:
No decimals stored.
Q2
Answer: B (false)
Why:
Q3
Answer: C (4)
Trace:
Values of i:
Stops after 10.
Total = 4 times
Q4
Correct array declaration?
Answer: C
Why others wrong:
-
A → missing []
-
B → invalid
-
D → C-style not Java
-
E → invalid syntax
Q5
Answer: D (5)
Why:
Q6
Which is infinite?
Answer: B
Always true → never stops.
Others modify variable or terminate.
Q7
Answer: B (2)
Why:
Arrays start at index 0:
Q8
Constructors:
Answer: B
Must have same name as class.
They:
-
have no return type
-
may have parameters
-
not static
Q9
Answer: B (8)
Why:
Math.pow returns double → prints 8.0 but closest answer is 8.
Q10
Prevents subclass modification?
Answer: C (final)
Why:
final:
-
prevents overriding
-
prevents inheritance (if class)
-
prevents reassignment (if variable)
✅ Section II — Free Response Solutions
Question 1 — countHotDays
Code
Explanation
Loop through all temperatures.
If ≥ 30 → increment counter.
Time complexity: O(n)
Question 2 — Book Class
Code
Explanation
-
Constructor initializes values
-
checkout → marks true
-
returnBook → false
-
isAvailable → opposite of checkedOut
Encapsulation using private.
Question 3 — ArrayList Scores
Assume:
(a) Average
Why:
Sum all values then divide.
(b) Remove below 50
Why backwards?
Removing shifts indices.
Backward prevents skipping.
(c) Highest score
Linear scan for maximum.
Question 4 — 2D Array GridGame
Assume:
(a) Count evens
(b) Largest value
(c) Replace negatives with 0
(d) Time complexity
Let:
We visit every element once:
Linear in total elements.
✅ Summary
MCQ Answers
1 B
2 B
3 C
4 C
5 D
6 B
7 B
8 B
9 B
10 C
Comments
Post a Comment