Instance method in AP Computer Science A
In AP Computer Science A, an instance method is a non-static method that belongs to an object of a class. You call it on a specific object using the dot operator, and inside it the keyword this refers to that object (EK 3.9.A.1). Class (static) methods have no this reference (EK 3.9.A.3).
What is instance method?
An instance method is a method that works on one particular object. You call it on that object with the dot operator, like myStudent.calculateGPA(). It isn't declared static, so it belongs to each object, not to the class as a whole.
Here's what makes an instance method special. When it runs, Java knows which object called it. Inside the method, the keyword this holds a reference to that current object (EK 3.9.A.1). That's how calculateGPA() reaches this student's grades and not some other student's. You can also pass this as an argument to another method, which hands over the current object itself (EK 3.9.A.2). Think of an instance method as a method that always carries a name tag saying "I'm running for this object." A class method doesn't have that name tag, so it has no this (EK 3.9.A.3).
Why instance method matters in AP® Computer Science A
Instance methods live in Unit 3: Class Creation, and the CED ties them directly to Topic 3.9 This Keyword. Learning objective AP Comp Sci A 3.9.A asks you to develop code for self-referencing expressions and figure out what they evaluate to. You can't do that without knowing that this only exists inside instance methods and constructors. Once you write your own classes, almost every behavior you give an object (getters, setters, calculations on its fields) is an instance method. Knowing when this is available, and what it points to, is how you trace code accurately and write class code that compiles.
Keep studying AP® Computer Science A Unit 3
How instance method connects across the course
The this Keyword (Unit 3)
this is the reason instance methods feel different from static ones. Every time an instance method runs, this quietly points at the object that called it. So this.hours means "the hours belonging to the object I was called on."
Class (Static) Methods (Unit 3)
Static methods belong to the class, not to any one object, so there's no current object for this to point to (EK 3.9.A.3). If a method never touches an object's attributes and is marked static, it's a class method, not an instance method.
Method Calls and the Dot Operator (Unit 1)
Before you write your own instance methods, you call them on objects like Strings. That object.method() syntax is the same idea from the other side. The object to the left of the dot is exactly what this refers to once you're inside the method.
Constructors (Unit 3)
Constructors get a this reference too (EK 3.9.A.1). That's why this.hours = hours; works in a constructor to tell the field apart from a parameter with the same name. It's the same trick you use inside instance methods.
Is instance method on the AP® Computer Science A exam?
Instance methods show up mostly in multiple-choice questions about tracing and classifying code. Expect stems like these:
- Classify the method. If a
Studentclass hascalculateGPA()that usesthisto read the current student's grades, it's an instance method. If a method is declaredstaticand never touches object attributes, it's a class method. - Trace self-referencing code. You'll see classes like
Timewith constructors such asthis.hours = hours; this.minutes = minutes;. You need to work out which variable is the field and which is the parameter, then predict the object's state. - Spot what won't compile. Using
thisinside a static method is an error, because class methods have nothisreference. - Constructor chaining. One practice item has a
Rectangleclass where a one-parameter constructor builds a square by calling the two-parameter constructor. That tests whether you understand howthisrefers to the current object being built.
No released FRQ has used the term verbatim. Still, the class-design FRQ asks you to write instance methods that read and update an object's private fields, so getting this right matters there too.
Instance method vs Class (static) method
An instance method is called on an object (s.calculateGPA()) and has a this reference to that object, so it can use that object's instance variables. A class method is declared static, belongs to the class itself, and has no this reference (EK 3.9.A.3). It can't directly use instance variables because there's no specific object in play. Quick test: if the method needs to know which object it's working on, it has to be an instance method.
Key things to remember about instance method
An instance method belongs to an object and is called on that object using the dot operator.
Inside an instance method, the keyword this refers to the current object, meaning the one the method was called on.
Class methods declared with static do not have a this reference, so using this inside them causes a compile error.
If a method reads or changes an object's instance variables, it should be an instance method, not a static method.
Writing this.field = field in a constructor or method assigns the parameter's value to the object's field when the two share a name.
You can pass the current object to another method by using this as an argument.
Frequently asked questions about instance method
What is an instance method in AP Computer Science A?
An instance method is a non-static method that belongs to an object and is called on it with the dot operator, like myRect.getArea(). Inside it, this refers to the object that called the method (EK 3.9.A.1).
Can you use this in a static method in Java?
No. Class (static) methods have no this reference (EK 3.9.A.3), because they aren't tied to any particular object. Trying to use this in one won't compile.
What's the difference between an instance method and a static method?
An instance method runs on a specific object and can use that object's fields through this. A static method belongs to the whole class, is called without needing an object, and has no this. A method marked static that does a calculation without touching object attributes is a class method.
Do constructors have a this reference like instance methods?
Yes. EK 3.9.A.1 says this is available within an instance method or a constructor. That's why this.hours = hours; in a Time constructor stores the parameter into the object's field.
Is a method that uses this always an instance method?
If it's a method (not a constructor) and it legally uses this, then yes, it's an instance method. For example, a calculateGPA() method that uses this to access the current student's grades is an instance method.
Keep studying AP Computer Science A
Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.
AP Computer Science A hub
Review units, study guides, and course resources.
AP-style practice
Check this vocabulary in multiple-choice context.
FRQ practice
Apply key concepts in written AP responses.
Score calculator
Estimate the exam score you are working toward.
Cheatsheets
Review the highest-yield facts before practice.
Practice exam
Put the full course together before test day.