Classes bundle data and behavior, protected by encapsulation
A class is a template that defines instance variables (an object’s state) and methods (its behavior). Good design uses abstraction to expose only what a user needs. Encapsulation keeps implementation details hidden: instance variables are declared private so outside classes can’t change them directly, while behavior is exposed through public methods. This protects an object’s state and lets the class control how it is used.
ClassEncapsulationprivate / public
Key Concept 2
Constructors and methods define how an object is built and used
A constructor (same name as the class, no return type) initializes a new object’s instance variables. Accessor (getter) methods return state without changing it, and mutator (setter) methods change it. Methods communicate through parameters and return values — and in Java, primitive arguments are passed by value, so a method works on a copy and cannot alter the caller’s original variable.
ConstructorAccessor / MutatorPass by Value
Key Concept 3
static members, scope, and this organize a class
A static variable or method belongs to the class rather than any object — there is a single shared copy, called with ClassName.member. Scope determines visibility: local variables live only inside their method, while instance variables are available throughout the object’s non-static methods. The this keyword refers to the current object and is used to distinguish an instance variable from a same-named parameter (this.field = field). Note that inheritance is outside the scope of AP CSA.
staticScopethis
Class
A template defining an object’s state and behavior.
Design
Abstraction
Hiding complexity, exposing only what is needed.
Design
Encapsulation
Hiding data with private and exposing behavior with public.
Design
public
Access allowed from any class.
Access
private
Access restricted to the declaring class.
Access
Instance variable
Per-object state; each object has its own copy.
State
Constructor
Initializes a new object; same name as class, no return type.
Methods
Default constructor
Provided by Java if none is written; sets fields to defaults.
Methods
Accessor (getter)
Returns an instance variable without changing it.
Methods
Mutator (setter)
Changes an instance variable; usually returns void.
Methods
Parameter
A variable in a method’s header.
Methods
Argument
The value passed to a method when called.
Methods
Pass by value
Primitive arguments are copied into parameters.
Methods
Return type
The type of value a method returns (or void).
Methods
static variable
A class-level variable shared by all objects.
static
static method
A class-level method called with ClassName.method().
static
Local variable
A variable visible only inside its method or block.
Scope
Scope
The region of code where a variable is accessible.