01
Overview

Classes: the blueprints that define your program.

A class describes what a kind of object knows and what it can do — and every object in your program is built from one.

A class is a Java construct that defines a new type. It bundles together data (instance variables) and behavior (methods), and tells Java how to build new objects with constructors.

Once you write a class, you can create many independent objects from it. A single Student class can power thousands of student objects, each with its own name, ID, and grades — all sharing the same behavior.

On the AP exam, you must be able to read, trace, and write classes. FRQ #2 is almost always a class-design question — and getting the class structure right is what separates a 4 from a 5.

02
Core Concept

A class has four parts.

Header, instance variables, constructors, methods — in that order.

Anatomy of a class

public class Student {

    // 1. Instance variables (state)
    private String name;
    private int grade;

    // 2. Constructor (initialization)
    public Student(String n, int g) {
        name = n;
        grade = g;
    }

    // 3. Accessor methods (read state)
    public String getName() {
        return name;
    }

    public int getGrade() {
        return grade;
    }

    // 4. Mutator method (change state)
    public void setGrade(int g) {
        grade = g;
    }
}

Using the class

Student s1 = new Student("Ana", 11);
Student s2 = new Student("Ben", 12);
s1.setGrade(12);
System.out.println(s1.getName() + " is in grade " + s1.getGrade());

Each call to new Student(...) creates a brand-new object with its own name and grade. The objects share the class's behavior, but each one has its own state.

One class, many objects

This is the core idea of object-oriented programming. Write the class once, then create as many objects as you need — each one independent.

File and naming rules

Public classes are stored in a file named exactly after the class (e.g. Student.java). Class names use PascalCase; variables and methods use camelCase.

03
Key Vocabulary

Vocabulary every class-design question uses.

Know these by sight to read FRQ prompts fast.

Vocabulary
  • Class — a blueprint that defines a new type.
  • Object / instance — one concrete value built from a class.
  • State — the current values stored in an object's instance variables.
  • Behavior — what an object can do, defined by its methods.
  • Class header — the line starting with public class.
  • Body — the code between the class's braces.
  • Client code — code outside the class that uses it.
  • Encapsulation — bundling data and behavior together inside a class.
04
AP Exam Focus

How class design is tested.

FRQ #2 is the big one; MCQs test structure recognition.

Exam Focus

What graders look for in a class FRQ:

  • Correct class header exactly as specified — name, no missing or extra modifiers.
  • Private instance variables with the exact names from the prompt.
  • Constructor with the exact signature given in the problem.
  • Public methods matching the signatures listed in the rubric.
  • No extra fields or methods unless they are clearly helpful and don't break encapsulation.

MCQs often show a class skeleton and ask which line of client code compiles, or which fields are accessible from outside the class.

05
Worked Example

Design a Book class from a written spec.

Convert plain-English requirements into a complete class.

Worked Example AP-style reasoning

Problem. Write a Book class that stores a title (String) and a number of pages (int). It should provide a constructor that takes both values, accessors for each, and a method isLong() that returns true if the book has more than 300 pages.

Step 1. Identify the state: two instance variables — title and pages. Make both private.

Step 2. Build the constructor with parameters in the order given.

Step 3. Add accessors (getTitle, getPages) and the behavior method isLong.

public class Book {
    private String title;
    private int pages;

    public Book(String t, int p) {
        title = t;
        pages = p;
    }

    public String getTitle() {
        return title;
    }

    public int getPages() {
        return pages;
    }

    public boolean isLong() {
        return pages > 300;
    }
}

Why this matters. The structure — private fields, constructor, accessors, behavior — is the template that earns full marks on FRQ #2. Memorize the pattern.

06
Common Mistakes

Class-design errors that cost FRQ points.

Almost all of these come from rushing past the prompt's exact wording.

Watch Out
  • Changing the class name or field names from what the prompt specifies.
  • Making fields public. AP rubrics expect private instance variables.
  • Adding a return type to the constructor. Constructors have no return type.
  • Forgetting accessor methods the prompt requires, then trying to access fields directly from client code.
  • Putting code in the wrong place. Statements belong inside methods, not directly in the class body.
  • Using static where instance is required. Static fields are shared across all objects, which usually breaks the design.
07
Reference Table

Parts of a class at a glance.

A checklist for any class you write on the AP exam.

Classes Reference

AP Quick Reference
Part Purpose AP Exam Tip
Class header Declares the new type Use public class + PascalCase name.
Instance variables Store each object's state Should be private.
Constructor Initializes new objects Same name as class; no return type.
Accessor methods Read state from outside Named getXxx; return matching type.
Mutator methods Change state from outside Named setXxx; usually void.
Behavior methods Compute or perform actions Implement the logic the prompt describes.
08
Practice Tip

How to master class design.

Repetition of the same template builds exam-ready muscle memory.

Practice Strategy

Use the three practice tools below this lesson in order:

  • MCQ Practice — recognize the parts of a class quickly. For each question, label fields, constructor, and methods before choosing.
  • Java Lab — build small classes from short specs: Rectangle, BankAccount, Song. Always start with private fields, then constructor, then accessors, then behavior.
  • FRQ Practice — write full class FRQs in 25 minutes. Match field and method names exactly. End with a quick reread to confirm visibility is correct.

If you can write a clean class from a one-paragraph spec, FRQ #2 becomes routine.

09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

Topic Quiz 30 min 29 marks Pending

AP CSA Topic Practice: Classes

AP-style topic practice assessment

Start
FRQ Practice 30 min 18 marks Pending

AP CSA Unit 03 Topic 01 Classes FRQ Practice

AP-style topic practice assessment

Start