Class Creation
What this unit covers
The topics below follow the published CS A course framework for Unit 3. This unit is worth 10–18% of the exam, so budget your time against that rather than against how long the unit takes to teach.
Lessons in this unit
- Writing Classes14 min · 3 objectivesIdentify the parts of a class: instance variables, a constructor, and methods · Trace object creation followed by method calls on that object · Distinguish methods that change state from methods that report it
- Instance Variables & this14 min · 3 objectivesExplain what the `this` keyword refers to inside a method · Use `this` to disambiguate a parameter from an instance variable · Recall the default values of uninitialized instance variables
- Encapsulation13 min · 3 objectivesExplain why instance variables are made `private` · Use public methods to read and modify private state safely · Recognize that accessing a private field from outside the class is illegal
- Inheritance (beyond the 2026 exam)14 min · 4 objectivesKnow that inheritance and polymorphism were removed from the AP CSA exam in the 2025 redesign — this lesson is background, not exam preparation · Use `extends` to create a subclass that inherits a superclass’s members · Predict which method runs when a subclass overrides a superclass method
Formulas in Unit 3
Every term in Unit 3
All 32 terms we publish for Class Creation, with definitions. Reading them through is the fastest way to find the ones you cannot define — then drill those in cram mode until you can produce them without the prompt.
- Class definition
- A blueprint declaring instance variables, constructors and methods. `public class Dog { ... }` — file name and public class name must match.
- Instance variable
- A variable declared in the class but outside any method, one copy per object. Conventionally private, and it holds an object's state.
- Local variable
- Declared inside a method or block, and it exists only while that block runs. It is not initialized automatically, unlike an instance variable.
- Scope
- The region where a name is usable. A local variable shadows an instance variable of the same name, which is why `this` is sometimes needed.
- Constructor
- A special method with the class's name and no return type, run when an object is created. It initializes the instance variables.
- Default constructor
- If a class declares no constructor at all, Java supplies a no-argument one. Writing any constructor removes that default, so `new Dog()` then fails to compile.
- Constructor overloading
- Several constructors with different parameter lists. Java picks by the arguments given at the call site.
- this
- A reference to the current object. `this.name = name;` distinguishes the instance variable from a parameter with the same name.
- Encapsulation
- Keeping instance variables private and exposing controlled access through methods. It lets the class guarantee its own state stays valid.
- Why instance variables are private
- Public fields let any code set an invalid value with no check. A private field with a setter can reject a negative age or a null name.
- Accessor (getter)
- A public method returning the value of a private instance variable, conventionally getX(). It should not change the object.
- Mutator (setter)
- A public method changing a private instance variable, conventionally setX(). The place to validate the new value.
- public vs private
- public members are usable anywhere; private members only inside the class. Constructors and methods intended for outside use are public; instance variables are private.
- static variable
- One copy shared by every object of the class, declared with `static`. Used for counts and constants rather than per-object state.
- static method
- Belongs to the class rather than an object, called as ClassName.method(). It cannot use `this` or read instance variables, because there is no object.
- Why a static method cannot use instance variables
- It can be called without any object existing, so there is no object whose variables to read. Attempting it is a compile error.
- final variable
- A variable that cannot be reassigned after initialization. Combined with static, it declares a constant: `public static final int MAX = 100;`
- toString
- A method returning a String description of the object. Java calls it automatically when an object is printed or concatenated with a String.
- Default toString
- Without your own toString, printing an object shows the class name and a hash code, which is almost never what a question wants.
- equals for your own class
- Compares the meaningful state of two objects. Without one, == compares references, so two objects with identical contents are unequal.
- Object state vs behavior
- State is what the instance variables hold; behavior is what the methods do. A well-designed class keeps state private and exposes behavior.
- Method decomposition
- Splitting a long method into smaller named ones. Each becomes testable and reusable, and the calling method reads as a summary.
- Return type of a constructor
- A constructor has none, not even void. Writing `public void Dog()` makes it an ordinary method rather than a constructor — and the class then has no constructor at all.
- Calling one constructor from another
- this(args) as the first statement of a constructor invokes another constructor of the same class, avoiding duplicated initialization.
- Instance variable default values
- Numeric fields default to 0, booleans to false, and references to null. Local variables get no default and must be assigned before use.
- Precondition
- What must be true when a method is called for it to work. Documented in a comment; the method is not required to check it.
- Postcondition
- What the method guarantees when it returns. Together with the precondition it forms the contract an FRQ expects you to honor.
- Writing a class from a specification
- Declare the private instance variables named in the spec, write the constructor to set them, then write each required method with the exact signature given. Changing a signature loses the point even if the logic is right.
- Accessing a private field of another object of the same class
- Allowed. Privacy is per class, not per object, so a method can read other.balance directly when other is the same type.
- Object reference aliasing
- Two variables referring to one object. Changing the object through either is visible through both — the source of many surprising trace answers.
- Immutability by design
- A class with private final fields and no mutators cannot change after construction, so it can be shared without copying. String is built this way.
- Class vs object on the exam
- A question asking "how many objects" is counting `new`. A question asking "how many classes" is counting blueprints. They are rarely the same number.
What examiners penalize here
- Track an object’s state across a sequence of calls by keeping a running note of each instance variable. Mutator calls change it; accessor calls only read it.
- Remember the split: **instance** variables default (int → 0, boolean → false, object → null), but **local** variables must be initialized before use or the code will not compile.
- On the exam, directly reading or writing a `private` field from outside its class is always an error. Legal access outside the class must go through a `public` method.
- **None of this is on the current exam.** The 2025 redesign of AP Computer Science A removed inheritance, polymorphism, `extends`, `super` and interfaces from the course. If you are revising for the exam, skip this lesson — Unit 3 is now tested on writing classes, instance variables, `this`, encapsulation, and static members and scope. This is here because inheritance is real Java that you will meet the moment you write code outside this course, and it costs you nothing to read once the exam is over.
- A subclass inherits public methods but not private fields directly — it reaches them through inherited methods or by passing values up with `super(...)`. `super(...)` must be the first line of the subclass constructor.
Practice CS A
Our practice bank is drawn from across the whole course rather than filtered to one unit, which is closer to how the exam asks anyway — it will not tell you which unit a question is testing.
Questions about this unit
How much of the AP Computer Science A exam is Unit 3?
Unit 3, Class Creation, is worth 10–18% of the CS A multiple-choice section according to the published course framework. Across all 4 units that makes it a substantial share — heavier than an even split would give it.
What topics are covered in CS A Unit 3?
Class Creation covers Writing classes, Instance variables & this, Encapsulation and Static members & scope. We publish 32 terms with definitions for this unit, all of them on this page.
How should I study CS A Unit 3?
Read the 4 lessons below first — about 55 minutes — then drill the 32 terms in cram mode until you can produce each definition from memory rather than just recognize it. Recognition is what makes a unit feel finished when it is not. Finish with practice questions and read the explanation for every one you get right by elimination as well as the ones you miss.
All 4 units of AP Computer Science A
Unit names, topics and exam weights follow the published College Board course framework for AP Computer Science A. AP® is a trademark registered by the College Board, which does not endorse this site.