Instance method in AP Computer Science A

In AP Computer Science A, an instance method is a method that belongs to an object of a class and is called on that object with the dot operator (like word.length()), giving it access to that specific object's instance variables (EK 1.14.A.1).

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is instance method?

An instance method is a behavior that belongs to a specific object, not to the class as a whole. You call it by writing the object's name, a dot, then the method name, like numbers.add(10) or c.increment(). The dot operator is literally how you tell Java "run this method on this particular object" (EK 1.14.A.1).

The big idea is that an instance method can read and change that object's instance variables. If you have two Counter objects and call increment() on one of them, only that one's count goes up. The other object is untouched. One critical rule from the CED: if the object reference is null, there's no object to act on, so calling any instance method on it throws a NullPointerException (EK 1.14.A.2). That single fact powers a huge number of MCQ traps.

Why instance method matters in AP® Computer Science A

Instance methods sit at the heart of Unit 1 (Using Objects and Methods) and come back in Unit 3 (Class Creation). LO 1.14.A asks you to call instance methods and trace what they do, which is basically the job description of the first half of the course. Then Topic 3.7 flips the question and makes you contrast instance methods with static (class) methods. Per EK 3.7.A.1, a class method cannot touch instance variables or call instance methods unless an object is passed in as a parameter, so knowing which kind of method you're looking at tells you exactly what data it can reach. Almost every line of object-oriented code you read or write on this exam, from String methods to ArrayList methods to methods in classes you design yourself, runs through this concept.

How instance method connects across the course

Static (Class) Methods (Unit 3)

Static methods are the mirror image of instance methods. They belong to the class itself, so all objects share them, and they're called with the class name like Math.sqrt(2). Because no specific object is attached, a static method can't access instance variables or call instance methods unless you hand it an object as a parameter (EK 3.7.A.1).

Dot Operator (Unit 1)

The dot operator is the syntax that makes instance methods work. word.length() reads as "go to the object that word refers to, and run length() on it." If you see objectName-dot-methodName, you're looking at an instance method call.

Null Reference (Unit 1)

A null reference points to no object at all, so there's nothing for an instance method to run on. Calling something like word2.toUpperCase() when word2 is null crashes with a NullPointerException (EK 1.14.A.2). That's why defensive code checks if (word2 != null) before making the call.

Is instance method on the AP® Computer Science A exam?

Instance methods show up constantly in multiple-choice code traces. A classic stem gives you a String or ArrayList and a chain of calls like numbers.add(10), numbers.get(1), numbers.set(0, value + 5), then asks what prints. You have to track how each call changes (or just reads) that specific object's state. Another favorite trap sets a reference to null and then calls a method on it, testing whether you know that produces a NullPointerException instead of output. In Unit 3 questions, you'll see a class definition like a Counter with increment() and getValue() and be asked which calls are legal or what the object's state is afterward. On the FRQs, especially Class design and Methods & Control Structures, you write instance methods yourself and call instance methods of other objects, so getting the object-dot-method pattern automatic is non-negotiable.

Instance method vs static method (class method)

An instance method is called on an object (myCounter.increment()) and can use that object's instance variables. A static method is called on the class (Math.abs(-5)) and cannot access instance variables or call instance methods at all, unless an object is passed to it as a parameter (EK 3.7.A.1). Quick check when reading code: name before the dot is an object, it's an instance method; name before the dot is a class, it's static.

Key things to remember about instance method

  • An instance method belongs to an object and is called with the object name plus the dot operator, like myList.add(5).

  • Instance methods can access and modify the instance variables of the specific object they're called on, which is how each object keeps its own state.

  • Calling an instance method on a null reference throws a NullPointerException, a fact the exam tests over and over (EK 1.14.A.2).

  • Static methods are the opposite case: they belong to the class, are called with the class name, and cannot touch instance variables or instance methods without being passed an object (EK 3.7.A.1).

  • Methods you use all course long, like String's length() and substring() or ArrayList's add(), get(), and set(), are all instance methods.

Frequently asked questions about instance method

What is an instance method in AP Computer Science A?

It's a method that belongs to an object of a class and is called on that object using the dot operator, like word.length() or numbers.add(10). Because it runs on a specific object, it can read and change that object's instance variables (EK 1.14.A.1).

What's the difference between an instance method and a static method?

An instance method is called on an object (c.increment()) and can use that object's instance variables. A static method is called on the class (Math.sqrt(2)) and can't access instance variables or call instance methods unless an object is passed in as a parameter (EK 3.7.A.1).

Do you need to create an object to call an instance method?

Yes. Instance methods only run on actual objects, so you need a constructed object first, like Counter c = new Counter(0); before calling c.increment(). Static methods are the ones you can call without any object.

What happens if you call an instance method on a null reference?

The program throws a NullPointerException (EK 1.14.A.2). If word2 is null, then word2.toUpperCase() crashes, which is exactly why exam code often checks if (word2 != null) before the call.

Are ArrayList methods like add and get instance methods?

Yes. add(), get(), set(), size(), and remove() are all instance methods because you call them on a specific ArrayList object, like numbers.get(1). Each call affects only that one list.