5m left·0%
Reading Time: 5 min
Last Updated: July 2, 2026
Main Ideas: 4
Reading Time: 5 min
Last Updated: July 2, 2026
Main Ideas: 4

Topic 1.12 Notes – Objects: Instances of Classes

Verified for 2027 AP® Computer Science A Exam
Read aloud
Objects are the actual things your program creates and uses at runtime. A class defines what those things look like and what they can do. This topic is about understanding that relationship, how objects are stored in memory, and how reference variables work.

What a Class Is vs What an Object Is

A class is the blueprint. It defines:

  • Instance variables → the data each object will store
  • Methods → the behaviors each object can perform

You write a class once in a .java file.

An object is a specific instance of that class. It:

  • Has its own copy of the instance variables
  • Uses the same method definitions as every other object of that class

If Book is a class, then:

Book b1 = new Book("1984", 328);
Book b2 = new Book("Dune", 412);

b1 and b2 are two different objects.

Even though they’re both Books, they store different data. Changing b1 does not change b2. That independence of state shows up constantly in multiple-choice tracing questions.

Classes as Types and Object Instantiation

Classes are data types, just like int or double.

When you write:

Book myBook;

You are declaring a variable of type Book.
You are not creating a Book yet.

To actually create the object:

Book myBook = new Book("Hamlet", 250);

That line does four things:

  1. new allocates memory for the object
  2. The constructor runs
  3. Instance variables are initialized
  4. myBook stores a reference to that object

Constructor Matching

A constructor:

  • Has the same name as the class
  • Has no return type
  • Must match the number, type, and order of arguments

If the constructor is:

public Book(String title, int pages)

Then this works:

Book b = new Book("Macbeth", 200);

But these cause compile-time errors:

  • Wrong order → new Book(200, "Macbeth")
  • Wrong type → new Book("Macbeth", "200")
  • Missing argument → new Book("Macbeth")

On tests, they love tiny parameter mismatches. Always check carefully.

Reference Variables and Memory

When you create an object, the variable does not store the object itself. It stores a reference to it.

Think of the variable as holding an address that points to an object in memory.

Two references pointing to the same Book object

Example:

Book b1 = new Book("1984", 328);
Book b2 = b1;

Now both b1 and b2 refer to the same object.

If you modify through one reference, the change is visible through the other. That’s because there is only one object in memory.

Null References

If you only declare:

Book b;

Then b is null.

Calling:

b.getTitle();

causes a NullPointerException.

Declaring a variable and instantiating an object are separate steps. This is one of the most common MCQ traps.

Inheritance and the Class Hierarchy

Sometimes classes are related.

If multiple classes share common data and behavior, you can place those in a superclass. Other classes can extend it as subclasses.

Example structure:

Study guide illustration

Simple class inheritance hierarchy

  • Vehicle → superclass
  • Car and Truck → subclasses

Subclasses:

  • Inherit accessible instance variables and methods
  • Do not need to rewrite that shared code

You are not required to design complex inheritance on the AP exam, but you must understand the relationship.

The Object Class

Every class in Java automatically extends the Object class.

Even if you don’t write:

public class Book extends Object

It’s still true. All classes are subclasses of Object.

Key Takeaways

A class defines attributes and behaviors; an object is a specific instance with its own data.
Variables of a class type store references, not the actual object.
Two variables can reference the same object, which means changes through one affect the other.
Declaring a reference variable without new leaves it null, and calling a method on it causes a NullPointerException.
Constructor calls must match parameter number, type, and order exactly.
Every class in Java is a subclass of Object, even if you never write it explicitly.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse this website.

Notes

1 credit used · 5/5 remaining