SAT / PSAT
SAT / PSAT Prep
History & Social Science
AP World History AP US History AP European History AP Human Geography AP US Government & Politics AP Psychology AP Macroeconomics AP Microeconomics
English
AP English Language & Composition AP English Literature & Composition
Math & Computer Science
AP Calculus AB/BC AP Precalculus AP Statistics AP Computer Science A AP Computer Science Principles
Sciences
AP Biology AP Chemistry AP Environmental Science AP Physics 1 AP Physics 2
World Languages & Arts
AP Spanish Language AP Art History AP Music Theory Start studying →
Unit 3 · Class Creation Flashcards Cheat Sheet Essentials Visual Review MC Practice FRQ Practice

AP Computer Science A Unit 3 FRQ Practice

Practice a College Board-style Class Design free response — instance variables, a constructor, accessor and mutator methods, and a static counter. Write your Java, then reveal the model answer to see exactly what earns each point.

← Back to Unit 3 hub
Free Response Question · Unit 3 · Class Creation

Design a class named BankAccount that stores a balance. This mirrors the exam’s Class Design question. The class should encapsulate its data.

A
Declare a private instance variable for the balance and write a constructor that initializes it from a parameter.

✓ Model answer

public class BankAccount {
  private double balance;

  public BankAccount(double startingBalance) {
    this.balance = startingBalance;
  }
}

Why it scores: Declares the instance variable as private (encapsulation), and the constructor has the class name, no return type, and initializes the field from the parameter. A return type on the constructor or a public field would lose points.
B
Write an accessor method getBalance and a mutator method deposit(double amount) that adds to the balance.

✓ Model answer

public double getBalance() {
  return balance;
}

public void deposit(double amount) {
  balance += amount;
}

Why it scores: The accessor returns the balance with the correct return type; the mutator returns void and updates the instance variable. Giving deposit a non-void return type, or having getBalance change state, would lose credit.
C
Add a static variable that counts how many BankAccount objects have been created, and explain why it is static.

✓ Model answer

private static int accountCount = 0;
… and inside the constructor add accountCount++;

It is static because the count belongs to the class as a whole, not to any single object — there is one shared copy that every constructor call increments, so all objects agree on the total.

Why it scores: Declares a static variable and increments it in the constructor, and correctly explains that a shared class-level count must be static (an instance variable would give each object its own separate counter).

How to score points on AP CSA free response