AP CSA Unit 3 Practice Exam: Class Creation (Part 1)

Unit 3: Class Creation

Part 1: Questions 1-25

Class Structure • Instance Variables • Constructors • The this Keyword

New AP CSA Curriculum (2025-2026): This exam covers Unit 3 (Class Creation) - designing classes, constructors, instance variables, methods, encapsulation, and static vs instance members. This is Part 1 of 2.
0 Correct | 0 Incorrect | 0/25 Answered
Class Structure & Instance Variables (Questions 1-12)
Question 1

Which access modifier should be used for instance variables to properly implement encapsulation?

Question 2

What is the default value of count when a Dog object is created?

public class Dog { private String name; private int age; private int count; }
Question 3

What is printed when this code runs?

public class Student { private String name; private double gpa; public void printInfo() { System.out.println(name + " " + gpa); } } // In main method: Student s = new Student(); s.printInfo();
Question 4

Which statement correctly describes instance variables?

Question 5

What is the best practice concern with this class?

public class Circle { public double radius; public double getArea() { return 3.14159 * radius * radius; } }
Question 6

What is printed?

public class Counter { private int value; public void increment() { value++; } public int getValue() { return value; } } // In main: Counter c1 = new Counter(); Counter c2 = new Counter(); c1.increment(); c1.increment(); c2.increment(); System.out.println(c1.getValue() + " " + c2.getValue());
Question 7

What is the default value of isActive when an Account object is created?

public class Account { private String owner; private double balance; private boolean isActive; }
Question 8

Which line causes a compile error?

public class BankAccount { private double balance; public double getBalance() { return balance; } } // In a separate class: public class Main { public static void main(String[] args) { BankAccount acct = new BankAccount(); double x = acct.balance; // Line A double y = acct.getBalance(); // Line B } }
Question 9

What does this code print?

public class Point { private int x, y; public void setLocation(int newX, int newY) { x = newX; y = newY; } public String toString() { return "(" + x + ", " + y + ")"; } } // In main: Point p = new Point(); p.setLocation(5, 10); System.out.println(p);
Question 10

What is the scope of the instance variable name?

public class Person { private String name; public void greet() { String greeting = "Hello, " + name; System.out.println(greeting); } }
Question 11

What happens when you compile this code?

public class Rectangle { private int width, height; public int getArea() { int result; result = width * height; return result; } }
Question 12

Which represents a "has-a" relationship (composition)?

// Option 1: public class Car { private Engine engine; } // Option 2: public class Car extends Engine { }
Constructors (Questions 13-25)
Question 13

What is printed?

public class Book { private String title; private int pages; public Book(String t, int p) { title = t; pages = p; } public void print() { System.out.println(title + ": " + pages); } } // In main: Book b = new Book("Java", 500); b.print();
Question 14

What is the result of this code? (Look carefully at the constructor!)

public class Cat { private String name; public Cat(String name) { name = name; // Bug here! } public String getName() { return name; } } // In main: Cat c = new Cat("Whiskers"); System.out.println(c.getName());
Question 15

What is the result with the fixed constructor using this?

public class Cat { private String name; public Cat(String name) { this.name = name; // Fixed! } public String getName() { return name; } } // In main: Cat c = new Cat("Whiskers"); System.out.println(c.getName());
Question 16

What happens when this code runs?

public class Employee { private String name; private double salary; public Employee(String n, double s) { name = n; salary = s; } } // In main: Employee e = new Employee();
Question 17

What is printed? (Constructor overloading)

public class Product { private String name; private double price; public Product() { name = "Unknown"; price = 0.0; } public Product(String n, double p) { name = n; price = p; } public void print() { System.out.println(name + ": $" + price); } } // In main: Product p1 = new Product(); Product p2 = new Product("Widget", 9.99); p1.print(); p2.print();
Question 18

Which statement about constructors is FALSE?

Question 19

What is printed? (Constructor chaining with this())

public class Timer { private int seconds; public Timer() { this(0); } public Timer(int s) { seconds = s; } public int getSeconds() { return seconds; } } // In main: Timer t = new Timer(); System.out.println(t.getSeconds());
Question 20

What is wrong with this constructor?

public class Game { private int score; public Game(int s) { System.out.println("Starting"); this(0); // Problem here score = s; } public Game() { score = 0; } }
Question 21

What does this refer to in a method?

public class Car { private String model; public Car(String model) { this.model = model; } public void compare(Car other) { if (this == other) { System.out.println("Same car!"); } } }
Question 22

What is printed?

public class Box { private int size; public Box() { this(10); size = size + 5; } public Box(int s) { size = s; } public int getSize() { return size; } } // In main: Box b = new Box(); System.out.println(b.getSize());
Question 23

How many times is the constructor called?

public class Item { private static int count = 0; public Item() { count++; } public static int getCount() { return count; } } // In main: Item a = new Item(); Item b = new Item(); Item c = a; System.out.println(Item.getCount());
Question 24

What is the primary purpose of a constructor?

public class Student { private String name; private int id; private double gpa; public Student(String name, int id) { this.name = name; this.id = id; this.gpa = 0.0; } }
Question 25

What is printed?

public class Temperature { private double celsius; public Temperature(double fahrenheit) { celsius = (fahrenheit - 32) * 5.0 / 9.0; } public double getCelsius() { return celsius; } } // In main: Temperature t = new Temperature(32); System.out.println(t.getCelsius());

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.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]