Free practice test — no login required
AP Computer Science A Practice Test (2027)
20 AP-style multiple-choice questions covering Unit 1 of AP Computer Science A. Pick an answer to get instant feedback with a full explanation — including why each wrong choice is wrong. Questions follow the College Board exam format for this subject.
Question 1
Topic 1.3: Calling MethodsConsider the following code: String str1 = "Hello"; String str2 = str1.concat(" World"); System.out.println(str1); What will be printed?
Question 2
Topic 1.3: Calling MethodsConsider this code: String word = "computer"; int index = word.indexOf("put"); What is the value of index?
Question 3
Topic 1.3: Calling MethodsA game development team is creating a Player class for their video game. Here is their current implementation: public class Player { private String name; private int health; private int score; public Player(String playerName) { name = playerName; health = 100; score = 0; } public void takeDamage(int damage) { health = health - damage; } public int getHealth() { return health; } } A programmer writes the following code: Player p = new Player("Alex"); p.takeDamage(25);
After this code executes, what will p.getHealth() return?
Question 4
Topic 1.3: Calling MethodsWhich of the following correctly demonstrates method chaining in Java?
Question 5
Topic 1.3: Calling MethodsConsider the following code: String message = "Java Programming"; String result = message.replace("a", "@"); What is the value of result?
Question 6
Topic 1.2: Creating ObjectsA class is intended to allow objects to be created in more than one way, as in `Rectangle r1 = new Rectangle(5);` and `Rectangle r2 = new Rectangle(5, 8);`. Which pair of constructor headers correctly overloads the constructor to support both statements?
Question 7
Topic 1.2: Creating ObjectsA software development team is creating a Student class for a school management system. They need to store information about each student including their name, ID number, and GPA. The following code snippet shows part of their implementation: public class Student { private String name; private int studentID; private double gpa; public Student(String n, int id, double g) { name = n; studentID = id; gpa = g; } }
Based on the code above, which statement about creating a Student object is correct?
Question 8
Topic 1.3: Calling MethodsConsider the following code: String text = "Programming"; String result = text.substring(3, 7); What is the value of result?
Question 9
Topic 1.3: Calling MethodsA programmer is working with the following Rectangle class: public class Rectangle { private double length; private double width; public Rectangle(double l, double w) { length = l; width = w; } public double getArea() { return length * width; } public double getPerimeter() { return 2 * (length + width); } } The programmer creates a Rectangle object with the following code: Rectangle rect = new Rectangle(5.0, 3.0);
What will be the result of calling rect.getPerimeter()?
Question 10
Topic 1.3: Calling MethodsWhat will happen if you try to call a method on a reference variable that has been assigned the value null?
Question 11
Topic 1.1: Objects and ClassesWhat does it mean for an instance variable to be declared as 'private' in Java?
Question 12
Topic 1.2: Creating ObjectsWhich of the following statements about the 'new' keyword in Java is most accurate?
Question 13
Topic 1.3: Calling MethodsWhich of the following best explains why we use the dot operator (.) in Java?
Question 14
Topic 1.1: Objects and ClassesA programmer writes the class header `public class Bicycle` and then writes `Bicycle b1 = new Bicycle("red", 21);` and `Bicycle b2 = new Bicycle("blue", 18);` inside a main method. Which of the following statements correctly describes what exists in the program?
Question 15
Topic 1.3: Calling MethodsA library system uses the following Book class: public class Book { private String title; private String author; private int pages; private boolean checkedOut; public Book(String t, String a, int p) { title = t; author = a; pages = p; checkedOut = false; } public void checkOut() { checkedOut = true; } public boolean isAvailable() { return !checkedOut; } } A librarian creates and uses a Book object as follows: Book novel = new Book("1984", "George Orwell", 328); novel.checkOut();
What will novel.isAvailable() return after this code executes?
Question 16
Topic 1.3: Calling MethodsConsider this code: String text = "Hello World"; String upper = text.toUpperCase(); String lower = upper.toLowerCase(); After this code executes, what are the values of text, upper, and lower?
Question 17
Topic 1.3: Calling MethodsConsider the following code: String str = "Hello World"; int length = str.length(); What is the value of length after this code executes?
Question 18
Topic 1.3: Calling MethodsA programmer is testing the following Circle class: public class Circle { private double radius; public Circle(double r) { radius = r; } public double getArea() { return Math.PI * radius * radius; } public double getCircumference() { return 2 * Math.PI * radius; } public void setRadius(double r) { radius = r; } } The programmer writes this test code: Circle c = new Circle(5.0); double area1 = c.getArea(); c.setRadius(10.0); double area2 = c.getArea();
What is the relationship between area1 and area2?
Question 19
Topic 1.1: Objects and ClassesWhich of the following best describes the relationship between a class and an object in Java?
Question 20
Topic 1.2: Creating ObjectsWhat is the purpose of a constructor in Java?
Want the full exam experience?
Unlock all 6 units of AP Computer Science A — 120 quiz questions, 5 classic practice exams with real timing, rubric-graded FRQs, and a 24/7 Socratic AI tutor. $7.99/month, 3-day free trial.