---
title: "Calling Instance Methods | AP Computer Science A 1.14"
description: "Review AP CSA 1.14 instance method calls, including object references, the dot operator, void and return-value methods, and NullPointerException errors."
canonical: "https://fiveable.me/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971"
type: "study-guide"
subject: "AP Computer Science A"
unit: "Unit 1 – Using Objects and Methods"
lastUpdated: "2026-06-09"
---

# Calling Instance Methods | AP Computer Science A 1.14

## Summary

Review AP CSA 1.14 instance method calls, including object references, the dot operator, void and return-value methods, and NullPointerException errors.

## Guide

Instance methods are [behaviors](/ap-comp-sci-a/key-terms/behavior "fv-autolink") that belong to specific objects, and you call them with the dot operator using the pattern `objectReference.methodName()`. Each object runs the method using its own data, so two objects of the same class can give different results. For [AP Computer Science A](/ap-comp-sci-a "fv-autolink"), check that the reference points to an object before tracing what the method call does.

## How Do You Call an Instance Method in Java?

Call an [instance method](/ap-comp-sci-a/key-terms/instance-method "fv-autolink") with an object reference, a dot, the method name, and [parentheses](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink"): `objectReference.methodName()`. The reference must point to an actual object; if it is `null`, the method call compiles but throws a `NullPointerException` when that line runs.

## Why This Matters for the AP Computer Science A Exam

This topic shows up constantly in AP Computer Science A because almost every program uses objects. On the multiple-choice section, you will trace code that creates objects and calls instance methods, then predict the output or spot why a line will not [compile](/ap-comp-sci-a/key-terms/compile "fv-autolink") or will crash. Knowing how the dot operator works, and when a `null` reference triggers a `NullPointerException`, helps you avoid common traps.

For free-response code writing, you call instance methods on objects you are given, including `String` objects and other provided classes. Being able to read a class and call its methods correctly is a skill you will use throughout the rest of the course, since later units build directly on this.

## Key Takeaways

- Instance methods are called on objects, using the dot operator: `objectReference.methodName()`.
- Each object runs an instance method using its own state, so the same method can produce different results on different objects.
- Calling any method on a `null` reference throws a `NullPointerException`, which is a run-time error, not a compile error.
- Instance methods differ from class ([static](/ap-comp-sci-a/unit-1/calling-non-void-method/study-guide/gXkdn6sNrkDRHZsCVN1x "fv-autolink")) methods, which are called on the class name instead of an object.
- Instance methods can be void or can return a value, just like other methods.
- Always make sure a reference actually points to an object (was assigned with `new` or set to an existing object) before calling a method on it.

## Key Concepts

### Instance Methods Belong to Objects

An instance method is a behavior that belongs to a specific object, not to the class itself. You need an actual object to call one. They are called "[instance](/ap-comp-sci-a/unit-1/objects-instances-of-classes/study-guide/EcpFHGcIKu6385hMohLe "fv-autolink")" methods because they work with instances (objects) of a class.

When you create an object using `new`, you can call any instance method defined in its class on that object. These methods can use that specific object's data, so each object can behave differently even though they share the same method code.

### The Dot Operator

The dot operator (`.`) is how you call an object's instance methods. The pattern is always `objectReference.methodName()`. The object reference tells Java which object should run the method, and the method name tells it what to do.

This creates a clear connection between the object and the action. When you write `myString.length()`, you are asking that particular `String` object for its length, not some other string. The dot operator only works when the reference actually points to an object.

### NullPointerException

A `null` reference is a [reference variable](/ap-comp-sci-a/key-terms/reference-variable "fv-autolink") that does not point to any object. If you try to call a method on a `null` reference, Java throws a `NullPointerException` at run time. The code compiles fine, but it crashes when that line runs.

This is one of the most common [run-time](/ap-comp-sci-a/unit-2/informal-code-analysis/study-guide/CR84MbOE4FDDoSVokDVZ "fv-autolink") errors. Any object reference that has not been assigned an object with `new` or set to an existing object can be `null`, so always check that a reference points to a real object before calling a method on it.

### Instance Methods Can Return Values or Be Void

Like any method, an instance method can return a value or be void. What makes it an instance method is that it is called on an object using the dot operator.

A method like `getDescription()` might return a value from the object, while `bark()` might be void but cause an action or change the [object's state](/ap-comp-sci-a/key-terms/objects-state "fv-autolink"). Both are instance methods because they need an object to be called on.

## Code Examples

A simple class to show instance method calls:

```java
// Example: Basic instance method calls
public class Dog {
    private String name;
    private int age;
    
    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }
    
    // Instance method - void return type
    public void bark() {
        System.out.println(name + " says: Woof!");
    }
    
    // Instance method - returns a value
    public String getDescription() {
        return name + " is " + age + " years old";
    }
    
    // Instance method that modifies object state
    public void haveBirthday() {
        age++;
        System.out.println(name + " is now " + age + "!");
    }
}

// Using the Dog class
public class DogPark {
    public static void main(String[] args) {
        // Create objects to call methods on
        Dog myDog = new Dog("Buddy", 3);
        Dog yourDog = new Dog("Max", 5);
        
        // Call instance methods using dot operator
        myDog.bark();                    // Prints: "Buddy says: Woof!"
        yourDog.bark();                  // Prints: "Max says: Woof!"
        
        // Call method that returns a value
        String description = myDog.getDescription();
        System.out.println(description); // Prints: "Buddy is 3 years old"
        
        // Call method that modifies state
        myDog.haveBirthday();           // Prints: "Buddy is now 4!"
    }
}
```

`String` methods are instance methods you will use constantly:

```java
// Example: String instance methods
public class StringMethodDemo {
    public static void main(String[] args) {
        String message = "Hello World";
        
        // length() is an instance method of String
        int len = message.length();  // Returns 11
        
        // substring() is an instance method that returns a new String
        String firstWord = message.substring(0, 5);  // "Hello"
        
        // Original string unchanged - String objects are immutable
        System.out.println(message);  // Still "Hello World"
        
        // Method chaining - calling instance methods one after another
        String result = message.substring(0, 5).substring(0, 3);  // "Hel"
    }
}
```

What happens with [null](/ap-comp-sci-a/key-terms/null "fv-autolink") references:

```java
// Example: Null reference problems and solutions
public class NullReferenceDemo {
    public static void main(String[] args) {
        String text = null;  // No actual String object
        
        // This would compile but crash at runtime!
        // int length = text.length();  // NullPointerException!
        
        // Safe approach - check for null first
        if (text != null) {
            int length = text.length();  // Only runs if text isn't null
            System.out.println("Length: " + length);
        } else {
            System.out.println("Text is null!");
        }
        
        // Another example with objects
        Dog noDog = null;
        // noDog.bark();  // Would throw NullPointerException!
        
        // Assign an object to avoid null
        Dog realDog = new Dog("Spot", 2);
        realDog.bark();  // Works fine - "Spot says: Woof!"
    }
}
```

Working with `ArrayList` instance methods:

```java
// Example: ArrayList instance methods
import java.util.ArrayList;

public class ArrayListDemo {
    public static void main(String[] args) {
        // Create ArrayList object
        ArrayList<String> names = new ArrayList<String>();
        
        // add() is an instance method
        names.add("Alice");    // Returns true
        names.add("Bob");      // Returns true
        
        // size() is an instance method  
        int count = names.size();  // Returns 2
        
        // get() is an instance method
        String first = names.get(0);  // Returns "Alice"
        
        // Multiple objects, same methods
        ArrayList<String> colors = new ArrayList<String>();
        colors.add("Red");
        colors.add("Blue");
        
        // Each object keeps its own state
        System.out.println(names.size());   // 2
        System.out.println(colors.size());  // 2
        // Same method, different objects, different results
    }
}
```

## How to Use This on the AP Computer Science A Exam

### Code Tracing

When you see a method call in exam code, first decide if it is a class (static) method or an instance method. If there is an object reference before the dot, it is an instance method call. This helps you read code quickly and spot errors.

For tracing problems, always check whether an object reference could be `null` before a method is called on it. The exam often hides this as a trap: code that looks fine but would crash with a `NullPointerException`.

Remember that each object runs an instance method on its own data, so the same method can return different values for different objects. Track each object's state separately as you trace.

### Free Response

When you write classes, you will call instance methods on objects you create or are given, including `String` objects and other provided classes. Use the dot operator with the correct object reference and pass arguments that match the method.

Inside a class, instance methods can use that object's instance variables, which is how you read and [update](/ap-comp-sci-a/unit-2/for-loops/study-guide/DJuLxKz6SiSAX2cEVmCt "fv-autolink") an object's state. Use that to fill in method bodies correctly rather than trying to reach into another object's [private data](/ap-comp-sci-a/unit-3/accessor-methods/study-guide/aGdfIlIw7aOvNseJG5R1 "fv-autolink") directly.

### Common Trap

- Trying to call an instance method without an object (writing `length()` instead of `text.length()`) will not compile.
- Mixing up static and instance calls: `Math.sqrt(16)` is a [class method](/ap-comp-sci-a/unit-3/this-keyword/study-guide/Zste3M7m756uzwR0zCQK "fv-autolink") called on the class, while `text.length()` is an instance method called on an object.
- Calling a method on a reference that is `null` compiles but crashes at run time.

## Common Misconceptions

- "A `NullPointerException` is a compile error." It is a run-time error. The code compiles, then crashes when the line with the `null` reference runs.
- "Instance methods change the object they are called on." Some do, but many just return a value without changing state. For example, `String` methods never change the original string because `String` objects are [immutable](/ap-comp-sci-a/key-terms/immutable "fv-autolink").
- "You can call any method using the class name." Only class (static) methods are called on the class name. Instance methods need an object reference and the dot operator.
- "If two objects are the same class, calling a method gives the same result." Each object has its own data, so the same instance method can return different results depending on the object's state.
- "An uninitialized object reference is ready to use." A reference that was never assigned an object is `null`, and calling a method on it throws a `NullPointerException`.

## Related AP Computer Science A Guides

- [1.10 Calling a Non-Void Method](/ap-comp-sci-a/unit-1/calling-non-void-method/study-guide/gXkdn6sNrkDRHZsCVN1x)
- [1.12 Objects: Instances of Classes](/ap-comp-sci-a/unit-1/objects-instances-of-classes/study-guide/EcpFHGcIKu6385hMohLe)
- [1.13 Creating and Storing Objects](/ap-comp-sci-a/unit-1/creating-and-storing-objects/study-guide/rUOTKl6Ih5noXJ0GtxJF)
- [1.15 String Methods](/ap-comp-sci-a/unit-1/string-methods/study-guide/SltCtk8JxBIgHcMfG6G4)
- [1.4 Assignment Statements and Input](/ap-comp-sci-a/unit-1/14-assignment-statement-input/study-guide/compoundassignment)
- [1.8 Documentation With Comments](/ap-comp-sci-a/unit-1/documentation-with-comments/study-guide/scrDad77j4e5vwrFab5J)
- [1.9 Calling a Void Method With Parameters](/ap-comp-sci-a/unit-1/calling-void-method-with-parameters/study-guide/QVWxxGeVjbIbLpC10d1Y)
- [1.6 Compound Assignment Operators](/ap-comp-sci-a/unit-1/compound-assignment-operators/study-guide/JiszeHqK8F9G6gszbgPL)
- [1.11 Using the Math Class](/ap-comp-sci-a/unit-1/using-the-math-class/study-guide/6e652tzJOa5eE5mjPATE)

## Vocabulary

- **NullPointerException**: An exception that occurs when a method is called on a null reference instead of a valid object.
- **dot operator**: The symbol (.) used in Java to access instance methods and properties of an object.
- **instance methods**: Methods that belong to an object and are called on specific instances of a class using the dot operator.
- **null reference**: A reference variable that points to no object, which will cause a NullPointerException if an instance method is called on it.

## FAQs

### How do you call an instance method in Java?

Use an object reference, the dot operator, the method name, and parentheses: objectReference.methodName(). Arguments go inside the parentheses if the method requires them.

### What does the dot operator do in Java?

The dot operator connects an object reference to a field or method. For instance methods, it tells Java which object should run the method.

### What happens if you call a method on null?

Calling a method on a null reference compiles but throws a NullPointerException when that line runs. The reference must point to an actual object before you call an instance method.

### What is the difference between an instance method and a static method?

An instance method is called on an object, such as text.length(). A static method is called on the class name, such as Math.sqrt(16).

### Can an instance method be void or return a value?

Yes. Instance methods can be void, meaning they do not return a value, or they can return a value. What makes them instance methods is that they are called on an object.

### How does Topic 1.14 show up on the AP CSA exam?

AP CSA questions often ask you to trace method calls, identify the object before the dot, determine returned values or side effects, and notice when a null reference would cause a NullPointerException.

## Structured Data

```json
{"@context":"https://schema.org","@type":"FAQPage","inLanguage":"en","mainEntity":[{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971#how-do-you-call-an-instance-method-in-java","name":"How do you call an instance method in Java?","acceptedAnswer":{"@type":"Answer","text":"Use an object reference, the dot operator, the method name, and parentheses: objectReference.methodName(). Arguments go inside the parentheses if the method requires them."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971#what-does-the-dot-operator-do-in-java","name":"What does the dot operator do in Java?","acceptedAnswer":{"@type":"Answer","text":"The dot operator connects an object reference to a field or method. For instance methods, it tells Java which object should run the method."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971#what-happens-if-you-call-a-method-on-null","name":"What happens if you call a method on null?","acceptedAnswer":{"@type":"Answer","text":"Calling a method on a null reference compiles but throws a NullPointerException when that line runs. The reference must point to an actual object before you call an instance method."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971#what-is-the-difference-between-an-instance-method-and-a-static-method","name":"What is the difference between an instance method and a static method?","acceptedAnswer":{"@type":"Answer","text":"An instance method is called on an object, such as text.length(). A static method is called on the class name, such as Math.sqrt(16)."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971#can-an-instance-method-be-void-or-return-a-value","name":"Can an instance method be void or return a value?","acceptedAnswer":{"@type":"Answer","text":"Yes. Instance methods can be void, meaning they do not return a value, or they can return a value. What makes them instance methods is that they are called on an object."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971#how-does-topic-114-show-up-on-the-ap-csa-exam","name":"How does Topic 1.14 show up on the AP CSA exam?","acceptedAnswer":{"@type":"Answer","text":"AP CSA questions often ask you to trace method calls, identify the object before the dot, determine returned values or side effects, and notice when a null reference would cause a NullPointerException."}}]}
```
