Object reference in AP Computer Science A

In AP Computer Science A, an object reference is the value a reference-type variable actually holds, which you can think of as the memory address of an object (EK 1.12.B.1). The variable doesn't contain the object itself, just directions to where it lives, or null if it points to nothing.

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

What is object reference?

When you write Student s = new Student();, the variable s does not hold the Student object. It holds an object reference, which the CED describes as something you can think of as the memory address of that object (EK 1.12.B.1). The object lives somewhere in memory, and the variable holds the directions to find it. If a reference variable doesn't point to any object yet, it holds null (EK 1.13.B.1).

This one idea explains a huge amount of weird-looking Java behavior. Two different variables can hold references to the same object, so changing the object through one variable changes what the other variable sees too (EK 2.6.B.1). Comparing references with == checks whether two variables point to the same object, not whether two objects look alike (EK 2.2.A.1). And when you pass an object to a method, Java copies the reference, not the object, so the method can reach back and modify the original mutable object (EK 3.6.A.1). Think of a reference like a home address written on a card. Copying the card doesn't build a second house, and anyone holding a copy can show up and repaint the real one.

Why object reference matters in AP® Computer Science A

Object references first appear in Unit 1, Topic 1.13 (Creating and Storing Objects), under LO 1.13.B, which asks you to declare variables of the correct types to hold object references. But the concept refuses to stay in Unit 1. LO 2.6.B (Unit 2) tests whether you can compare references with ==, !=, and null. LO 3.6.A (Unit 3) tests whether you understand that methods receive a copy of the reference, which is why a method can mutate an object passed to it. In Unit 4, arrays of objects store references (EK 4.3.A.1) and default to null (EK 4.3.A.3), ArrayLists contain object references (EK 4.8.A.1), and the enhanced for loop variable gets a copy of each element's reference, which is exactly why reassigning it does nothing (EK 4.4.A.4). If you misunderstand references, you will misread code in all four units. If you get them, half of Java's "gotcha" questions stop being gotchas.

How object reference connects across the course

== (Equality Operator) and equals (Unit 2)

With reference types, == compares the references themselves, asking "do these two variables point to the same object in memory?" (EK 2.2.A.1, EK 2.6.B.1). The equals method, defined by a class, compares object contents instead. Two Strings with identical text can be equals but not ==.

Call by Value (Units 1 & 3)

Java always passes arguments by value, but for objects the value being copied is the reference (EK 3.6.A.1). So the method gets its own copy of the address, not a copy of the object, which is why a method can change the state of a mutable object you pass in.

Array Creation and Access (Unit 4)

An array of objects is really an array of references, and new fills it with the default value null (EK 4.3.A.3). That's why calling a method on an element of a freshly created object array throws a NullPointerException until you actually construct objects for each slot.

ArrayList Methods (Unit 4)

EK 4.8.A.1 says it directly. An ArrayList contains object references. Methods like .get() hand back the reference to the stored object, not a copy of it, so modifying what .get() returns modifies the object inside the list.

Is object reference on the AP® Computer Science A exam?

Object references show up constantly in multiple-choice code-tracing questions. Common stems ask which declaration correctly holds a reference to an object of a given class, which superclass-typed variable can store references to multiple subclass objects (like a Vehicle variable holding Car and Truck references), and what == returns when two variables reference the same or different objects. You'll also trace code where two variables alias the same object and predict the output after one of them mutates it. On FRQs, references matter implicitly every time you write a method that takes an object parameter or returns an object. Remember that returning an object returns the reference, not a fresh copy (EK 3.6.A.2), and that checking a reference against null before calling methods on it is often the difference between full credit and a logic error.

Object reference vs Object (the instance itself)

The object is the actual instance sitting in memory with its attributes; the reference is the address-like value your variable holds that points to it (EK 1.12.A.1, EK 1.12.B.1). The line Student s; creates a reference variable but zero objects. Only new Student() builds an actual object. Mixing these up is why null errors and aliasing bugs feel mysterious. One object can have many references pointing at it, and a reference can exist with no object behind it at all.

Key things to remember about object reference

  • A reference-type variable holds an object reference, which works like the memory address of the object, or null if no object exists yet (EK 1.12.B.1, EK 1.13.B.1).

  • Two different variables can reference the same object, so a change made through one variable is visible through the other (EK 2.6.B.1).

  • Using == on reference types compares the references, not the contents of the objects; use the class's equals method to compare contents (EK 2.2.A.1, EK 2.6.B.3).

  • When an object is passed to a method, the parameter gets a copy of the reference, so the method can alter a mutable object's state but reassigning the parameter does nothing to the caller's variable (EK 3.6.A.1).

  • Arrays and ArrayLists of objects actually store references, and object array elements default to null when the array is created (EK 4.3.A.3, EK 4.8.A.1).

  • Assigning a new value to an enhanced for loop variable doesn't change the array, because that variable holds only a copy of each element's reference (EK 4.4.A.4).

Frequently asked questions about object reference

What is an object reference in AP Computer Science A?

It's the value a reference-type variable holds, which the CED says you can think of as the memory address of an object (EK 1.12.B.1). The variable points to the object rather than containing it, and it holds null if there's no object.

Does == compare objects in Java?

No, not their contents. For reference types, == compares the references, so it returns true only when both variables point to the exact same object in memory (EK 2.2.A.1). To compare what's inside two objects, use the class's equals method.

What's the difference between an object and an object reference?

The object is the instance itself, created with the keyword new and a constructor call (EK 1.13.C.1). The reference is the address-like value stored in your variable that points to that object. Declaring a variable creates a reference slot but never creates an object.

If Java is call by value, why can a method change my object?

Because the value being copied is the reference. The method gets its own copy of the address, follows it to the same object, and can mutate that object's state (EK 3.6.A.1). It can't, however, make your original variable point somewhere new.

Why do I get a NullPointerException with a new array of objects?

When you create an object array with new, every element defaults to null (EK 4.3.A.3). The array holds references, not objects, so you have to construct an object for each index before calling methods on the elements.