Free practice test — no login required

AP Computer Science A Practice Test (2026)

18 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.

0 / 18 answered0 correct

Question 1

Topic 1.1: Objects and Classes

Which of the following best describes the relationship between a class and an object in Java?

Question 2

Topic 1.3: Calling Methods

Consider the following code:\n\nString str = "Hello World";\nint length = str.length();\n\nWhat is the value of length after this code executes?

Question 3

Topic 1.3: Calling Methods

Which of the following correctly demonstrates method chaining in Java?

Question 4

Topic 1.2: Creating Objects

What is the purpose of a constructor in Java?

Question 5

Topic 1.2: Creating Objects
A 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:\n\npublic class Student {\n private String name;\n private int studentID;\n private double gpa;\n \n public Student(String n, int id, double g) {\n name = n;\n studentID = id;\n gpa = g;\n }\n}

Based on the code above, which statement about creating a Student object is correct?

Question 6

Topic 1.3: Calling Methods

Consider the following code:\n\nString text = "Programming";\nString result = text.substring(3, 7);\n\nWhat is the value of result?

Question 7

Topic 1.2: Creating Objects

Which of the following statements about the 'new' keyword in Java is most accurate?

Question 8

Topic 1.3: Calling Methods

Consider this code:\n\nString word = "computer";\nint index = word.indexOf("put");\n\nWhat is the value of index?

Question 9

Topic 1.3: Calling Methods
A programmer is working with the following Rectangle class:\n\npublic class Rectangle {\n private double length;\n private double width;\n \n public Rectangle(double l, double w) {\n length = l;\n width = w;\n }\n \n public double getArea() {\n return length * width;\n }\n \n public double getPerimeter() {\n return 2 * (length + width);\n }\n}\n\nThe programmer creates a Rectangle object with the following code:\nRectangle rect = new Rectangle(5.0, 3.0);

What will be the result of calling rect.getPerimeter()?

Question 10

Topic 1.1: Objects and Classes

What does it mean for an instance variable to be declared as 'private' in Java?

Question 11

Topic 1.3: Calling Methods

Consider the following code:\n\nString str1 = "Hello";\nString str2 = str1.concat(" World");\nSystem.out.println(str1);\n\nWhat will be printed?

Question 12

Topic 1.3: Calling Methods
A game development team is creating a Player class for their video game. Here is their current implementation:\n\npublic class Player {\n private String name;\n private int health;\n private int score;\n \n public Player(String playerName) {\n name = playerName;\n health = 100;\n score = 0;\n }\n \n public void takeDamage(int damage) {\n health = health - damage;\n }\n \n public int getHealth() {\n return health;\n }\n}\n\nA programmer writes the following code:\nPlayer p = new Player("Alex");\np.takeDamage(25);

After this code executes, what will p.getHealth() return?

Question 13

Topic 1.3: Calling Methods

Which of the following best explains why we use the dot operator (.) in Java?

Question 14

Topic 1.3: Calling Methods

Consider the following code:\n\nString message = "Java Programming";\nString result = message.replace("a", "@");\n\nWhat is the value of result?

Question 15

Topic 1.3: Calling Methods
A library system uses the following Book class:\n\npublic class Book {\n private String title;\n private String author;\n private int pages;\n private boolean checkedOut;\n \n public Book(String t, String a, int p) {\n title = t;\n author = a;\n pages = p;\n checkedOut = false;\n }\n \n public void checkOut() {\n checkedOut = true;\n }\n \n public boolean isAvailable() {\n return !checkedOut;\n }\n}\n\nA librarian creates and uses a Book object as follows:\nBook novel = new Book("1984", "George Orwell", 328);\nnovel.checkOut();

What will novel.isAvailable() return after this code executes?

Question 16

Topic 1.3: Calling Methods

What will happen if you try to call a method on a reference variable that has been assigned the value null?

Question 17

Topic 1.3: Calling Methods

Consider this code:\n\nString text = "Hello World";\nString upper = text.toUpperCase();\nString lower = upper.toLowerCase();\n\nAfter this code executes, what are the values of text, upper, and lower?

Question 18

Topic 1.3: Calling Methods
A programmer is testing the following Circle class:\n\npublic class Circle {\n private double radius;\n \n public Circle(double r) {\n radius = r;\n }\n \n public double getArea() {\n return Math.PI * radius * radius;\n }\n \n public double getCircumference() {\n return 2 * Math.PI * radius;\n }\n \n public void setRadius(double r) {\n radius = r;\n }\n}\n\nThe programmer writes this test code:\nCircle c = new Circle(5.0);\ndouble area1 = c.getArea();\nc.setRadius(10.0);\ndouble area2 = c.getArea();

What is the relationship between area1 and area2?

Want the full exam experience?

Unlock all 6 units of AP Computer Science A 120 quiz questions, 5 full-length practice exams with real timing, rubric-graded FRQs, and a 24/7 Socratic AI tutor. $7.99/month, 3-day free trial.