Unit 3: Class Creation

Writing your own classes β€” and collecting the most predictable FRQ points on the exam.

10–18% of the AP CSA exam Β· FRQ 2 is always "write a class"

Home β†’ Unit 3

The anatomy of a class (memorize this shape)

FRQ 2 hands you a description and asks for a complete class. The structure is the same every year β€” private instance variables, a constructor that initializes all of them, and methods. Learn the shape once, collect the points every time.

public class BankAccount {
    // 1. instance variables β€” ALWAYS private
    private String owner;
    private double balance;

    // 2. constructor β€” same name as class, no return type
    public BankAccount(String o, double b) {
        owner = o;
        balance = b;
    }

    // 3. methods β€” accessor (returns info)…
    public double getBalance() {
        return balance;
    }

    // …and mutator (changes state)
    public void deposit(double amount) {
        balance += amount;
    }
}

How the FRQ is graded (and where points leak)

Graders award points for: the class header, private instance variables, a working constructor, correct method signatures, and correct method logic. The signatures are free points β€” copy the method names, parameter types, and return types exactly as the problem states them. A typo in a signature can cost the point even if your logic is perfect.

this and object references

When a parameter name shadows an instance variable, this.name = name; says "the object's variable = the parameter." Avoid the issue entirely by giving parameters different names (like o and b above) β€” allowed, simpler, fewer mistakes under time pressure.

Try it β€” exam-style questions

1. Which line correctly declares a constructor for a class named Player?
2. Why should instance variables be private?
3. What does this print?
public class Counter {
    private int count;
    public Counter() { count = 0; }
    public void bump() { count += 2; }
    public int getCount() { return count; }
}
// elsewhere:
Counter c = new Counter();
c.bump();
c.bump();
c.bump();
System.out.println(c.getCount());
4. A method that returns the owner's name but doesn't change anything should be declared:

⚠ Common mistakes that cost points

Want your practice FRQs graded like the real thing?

I grade them the way readers do β€” point by point, with the why. It's the fastest FRQ improvement there is.

Ask about tutoring →