Methods: an object's behaviors.
Methods are how clients interact with an object's state — to read it, change it, or compute something new from it.
A method is a named block of code inside a class. Instance methods act on a specific object's state; static methods act on the class as a whole.
In a well-designed class, you'll see three common types of methods: accessors (read state), mutators (change state), and behavior methods (compute or perform actions). Together they form the object's public interface.
On the AP exam, methods are tested everywhere: MCQs check signatures, FRQ class design demands you write multiple methods, and method method-implementation FRQs test your ability to traverse data and return results.
Accessors, mutators, and behavior methods.
Each plays a distinct role in the class's public interface.
Method header
public returnType methodName(parameters) {
// body
}
The combination of name + parameter types is the method's signature. The return type is part of the header but not the signature.
Accessor (getter) methods
public String getName() {
return name;
}
Returns the value of a field. Usually named getXxx. Has no parameters. Return type matches the field's type.
Mutator (setter) methods
public void setName(String n) {
name = n;
}
Updates a field. Usually named setXxx. Usually void. Takes one parameter that matches the field's type.
Behavior methods
public double area() {
return width * height;
}
Performs a computation or action involving the object's state. Can have any return type, including void.
Static vs instance methods
- Instance method — operates on a specific object's fields. Called with
obj.method(). - Static method — belongs to the class itself. Called with
ClassName.method(). Cannot directly access instance variables.
Helper methods
Private methods used internally by the class to break complex logic into manageable steps. They are not part of the public interface.
private boolean isValid(int n) {
return n >= 0 && n <= 100;
}
Method terminology AP uses precisely.
The right vocabulary makes FRQ rubrics easier to satisfy.
- Method — a named block of code in a class.
- Accessor / getter — returns the value of a field.
- Mutator / setter — modifies the value of a field.
- Behavior method — performs a computation or action.
- Helper method — internal, usually
private, used by other methods. - Method signature — name plus ordered list of parameter types.
- Method overloading — multiple methods with the same name but different parameter lists.
- Public interface — the set of public methods clients can call.
How methods are tested.
Signatures, return values, and access patterns dominate.
What FRQs grade:
- Exact method header. Name, parameter types, return type all match the prompt.
- Correct return value. The method returns what the rubric requires on every input.
- Proper field access. Inside the class, read and write fields directly rather than going through your own getters.
- No public fields. Use methods to expose data, not direct field access.
MCQs frequently test overloading (which method gets called?) and method calls on objects (what does the receiver look like?).
Write a complete method set for a class.
Apply the accessor / mutator / behavior pattern.
Problem. A BankAccount class has a private double balance. Write methods to read the balance, deposit money (positive amounts only), and check if the account is overdrawn (balance is negative).
Step 1. Accessor: returns the balance.
Step 2. Mutator: deposits a positive amount. Use a guard so invalid input is ignored.
Step 3. Behavior method: returns whether the balance is negative.
public double getBalance() {
return balance;
}
public void deposit(double amount) {
if (amount > 0) {
balance = balance + amount;
}
}
public boolean isOverdrawn() {
return balance < 0;
}
Why this matters. The trio of accessor, mutator-with-validation, and behavior method is the AP CSA template for nearly every class-design FRQ. Add validation in mutators only when the prompt specifies it.
Method errors that lose FRQ points.
Most come from signature drift and ignoring return values.
- Wrong return type. A getter for a
Stringfield must returnString, notvoid. - Forgetting the return statement in a non-
voidmethod. - Wrong parameter list. Match types and order exactly to the prompt.
- Making methods
static. An accessor reads this object's field, so it cannot be static. - Calling your own getters and setters from inside the class. Cleaner to access fields directly when inside the class.
- Mutating in an accessor. An accessor should only return; never change state inside a
getXxx.
Method types at a glance.
Identify each method by its job before writing it.
Methods Reference
AP Quick Reference| Type | Job | AP Exam Tip |
|---|---|---|
| Accessor (getter) | Return a field's value | No parameters; return type = field type. |
| Mutator (setter) | Change a field's value | Usually void; one parameter. |
| Behavior method | Compute or perform an action | Any return type; uses fields and parameters. |
| Helper method | Internal subroutine | Make it private; not part of public API. |
| Static method | Belongs to the class | Cannot access instance variables directly. |
| Overloaded methods | Same name, different parameter lists | Java chooses by argument types. |
How to make method writing automatic.
A consistent template lets you focus on logic, not structure.
Use the three practice tools below this lesson in order:
- MCQ Practice — for each question, name the method type (accessor / mutator / behavior) and predict the return type before evaluating the options.
- Java Lab — implement complete method sets for small classes. Write the header exactly as a prompt would phrase it, then the body.
- FRQ Practice — copy method headers from the prompt before writing the body. Make sure every non-
voidmethod ends with a return.
If you can describe each method as "reads", "writes", or "does", you've already half-written it.
Practice — attempt these now.
AP-style assessments aligned to this lesson. Time them.