All 4 CS A units
AP Computer Science A · Unit 3 of 4

Class Creation

10–18% of the exam4 lessons · 55 min32 terms

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.

Writing classesInstance variables & thisEncapsulationStatic members & scope

Lessons in this unit

Formulas in Unit 3

A minimal class
class C { private T field; C(T v){ field = v; } T getField(){ return field; } }
Instance variable + constructor + accessor is the core shape of nearly every AP class.
this to resolve shadowing
public Point(int x) { this.x = x; }
`this.x` is the instance variable; the bare `x` is the parameter. `this` picks the field when the names collide.
Encapsulation pattern
private field + public getter/setter = controlled access
Data is hidden; all reads and writes flow through methods the class controls.
Subclass with super call
class Sub extends Super { Sub(){ super(args); } }
`super(args)` runs the superclass constructor first, initializing inherited fields before the subclass adds its own setup.

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

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

  1. Unit 1 · Using Objects and Methods
  2. Unit 2 · Selection and Iteration
  3. Unit 3 · Class Creation
  4. Unit 4 · Data Collections

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.