Home ›
AP Computer Science A ›
Unit 3 ›
Visual Review
AP Computer Science A Unit 3 Visual Review
A topic-by-topic visual walkthrough of Class Creation — abstraction, constructors, writing methods, class variables, scope and access, and the this keyword.
← Back to Unit 3 hub
TOPIC 3.1
Abstraction and Program Design
Abstraction hides complexity
A class lets you use an object through
its methods WITHOUT knowing how
they're implemented inside.
You drive a car without knowing the engine.
Procedural abstraction
A method names a task so you can call it
by name instead of rewriting the steps.
This reduces repetition and makes code
easier to read, test, and reuse.
Designing a class: identify state and behavior
STATE = the data an object stores (instance variables). BEHAVIOR = what it can do (methods).
A BankAccount has state (balance) and behavior (deposit, withdraw). Model the nouns as data, verbs as methods.
Abstraction hides detail ; design a class around its state (data) and behavior (methods).
The Review Hub · AP Computer Science A Unit 3
TOPIC 3.2
Impact of Program Design
Software affects real people — design responsibly
Programs have ethical and social consequences. Developers should consider bias, accessibility, privacy,
and the impact on users when they design and test software.
Good practices
• Test with diverse inputs & users.
• Consider edge cases and misuse.
• Protect user data and privacy.
• Design for accessibility.
Where bias creeps in
Programs reflect the assumptions and
data of the people who build them.
Unrepresentative test data can produce
outcomes that harm some groups.
Thoughtful design reduces unintended harm.
Program design has ethical and social impact — test broadly and protect users.
The Review Hub · AP Computer Science A Unit 3
TOPIC 3.3
Anatomy of a Class
public class Student {
// instance variables (state)
private String name;
private int gpa;
// constructor
Student (String n) { name = n; }
// method (behavior)
String getName () { return name; }
}
Three parts
• INSTANCE VARIABLES hold state.
• CONSTRUCTORS set up new objects.
• METHODS define behavior.
Encapsulation
Mark instance variables private so
outside code can't change them
directly — only through methods.
A class holds private instance variables, constructors, and methods .
The Review Hub · AP Computer Science A Unit 3
TOPIC 3.4
Constructors
public Student (String n, int g) { // same name as the class, NO return type
name = n;
gpa = g; }
Sets the initial state
Runs once, when new creates the object.
Its parameters set the instance variables.
Name matches the class; has NO return type
(not even void).
Overloading & defaults
A class can have MULTIPLE constructors
with different parameter lists (overloading).
Uninitialized fields default to 0, 0.0,
false, or null.
A constructor shares the class name, has no return type, and sets initial state.
The Review Hub · AP Computer Science A Unit 3
TOPIC 3.5
Methods: How to Write Them
public double average (int a, int b) {
return (a + b) / 2.0; // must return a double
}
The return statement
A non-void method MUST return a value
matching its declared return type.
return also ENDS the method
immediately.
void vs. returning
void: performs an action, returns nothing.
A void method may use a bare "return;"
to exit early.
Parameters are local copies (see 3.6).
A method's return type must match what it returns ; return also exits the method.
The Review Hub · AP Computer Science A Unit 3
TOPIC 3.6
Passing & Returning Object References
Primitives: passed by VALUE
A method gets a COPY of an int/double/
boolean.
Changing the parameter inside does
NOT affect the caller's variable.
The original value is untouched.
Objects: reference is copied
A method gets a copy of the REFERENCE,
so it points at the SAME object.
Calling a mutator through it DOES change
the caller's object.
Reassigning the parameter does not.
// list still points to the same object the method modified
addItem(cart); // cart's contents change for the caller too
Primitives pass by value (a copy) ; objects pass a reference to the SAME object.
The Review Hub · AP Computer Science A Unit 3
TOPIC 3.7
Class Variables and Methods (static)
static = belongs to the CLASS
A static (class) variable is SHARED by
every object — there's only one copy.
An instance variable is separate for
each object.
static int count = 0;
// count new objects made
static int total = 0 ;
Cat () {
total++; // shared
}
Cat.total // access on class
Static methods can't touch instance data
A static method has no "this" object, so it can only use static variables and its own parameters.
static members belong to the class and are shared across all objects.
The Review Hub · AP Computer Science A Unit 3
TOPIC 3.8
Scope and Access
Scope = where a name is visible
A LOCAL variable exists only inside the
method (or block) that declares it.
An INSTANCE variable is visible to all
methods of the class.
public vs. private
public: accessible from other classes.
private: only within THIS class.
Fields are usually private; methods that
form the interface are public.
Encapsulation with getters & setters
Keep data private and expose ACCESSORS (getName) and MUTATORS (setName). This lets the class
control and validate every change to its state, protecting it from invalid values.
Local scope is per-method ; keep fields private, expose behavior through public methods.
The Review Hub · AP Computer Science A Unit 3
TOPIC 3.9
The this Keyword
public void setName (String name) {
this .name = name; // field = parameter
}
this = "the current object"
Inside an instance method, this refers to
the object the method was called on.
this.field reaches an instance variable
even when a parameter has the same name.
Resolving shadowing
When a parameter "shadows" a field (same
name), this.name is the field, name is
the parameter.
Only instance (non-static) methods have this.
this refers to the current object — use this.field when a parameter shares the name.
The Review Hub · AP Computer Science A Unit 3
▤ Show all slides
How to use the visual review
Spend 30 seconds per slide before clicking next. Look at the code, then ask yourself: "Could I write this class part from memory?"
Use the fullscreen button () on desktop for the best experience. Use arrow keys to navigate. Tap "Show all slides" to jump around.
This is great for review the night before the exam — fast, visual, and covers every idea you need to recognize in Unit 3.