7m left·0%
Reading Time: 7 min
Last Updated: February 18, 2026
Main Ideas: 5
Reading Time: 7 min
Last Updated: February 18, 2026
Main Ideas: 5

Topic 1.13 Notes – Object Creation and Storage (Instantiation)

Verified for 2027 AP® Computer Science A Exam
Read aloud
Object creation is how your program turns a class blueprint into a real, usable object in memory. This topic focuses on constructors, how Java decides which one to call, how new works, and how object references store and access those created objects. It’s the foundation of everything you’ll do with classes.

What Constructors Are and How They Are Identified

A constructor is a special method that runs when you create a new object.

You can spot one because:

  • It has the same name as the class.
  • It has no return type (not even void).
  • It runs automatically when you use new.

Example:

public class Player {
    private String name;
    private int score;

    public Player(String n, int s) {
        name = n;
        score = s;
    }
}

That Player(String n, int s) is the constructor.

Constructor Signature

The signature determines which constructor gets called.

Signature = constructor name + ordered list of parameter types

Important details:

  • Parameter names do not matter.
  • Order matters.
  • Types matter.

So these are different:

Player(String name, int score)
Player(int score, String name)

Same types, different order → different signatures.

On multiple choice, they love giving you several constructors and asking which line compiles. Match:

  1. Number of arguments
  2. Types
  3. Order

Miss one of those and it won’t match.

Overloaded Constructors

A class can have multiple constructors as long as their signatures are different. That’s called constructor overloading.

Example:

public Player(String n) {
    name = n;
    score = 0;
}

public Player(String n, int s) {
    name = n;
    score = s;
}

Java chooses based on the arguments you pass:

Player p1 = new Player("Alex");       // first constructor
Player p2 = new Player("Jamie", 10);  // second constructor

If no constructor matches exactly, you get a compile-time error.

Object References and Variable Declarations

When you declare an object variable:

Player p;

You are creating a reference variable.

That variable:

  • Can store a reference to a Player object
  • Or can store null

The object itself lives somewhere in memory. The variable just holds the reference (address) to it.

Here’s the mental model. Focus on how the variables in the stack point to objects in the heap:

Study guide illustration

Stack and heap memory with object references

Key ideas:

  • Multiple variables can refer to the same object.
  • Assigning one reference to another does not create a new object.
  • If a reference hasn’t been assigned an object, it is null.

Example:

Player p1 = new Player("Alex", 5);
Player p2 = p1;

Now p1 and p2 point to the same object. Changing through one affects the same object.

This shows up on tests when they ask whether two variables refer to the same object or different ones. Track arrows, not names.

Creating Objects with new

Standard pattern:

ClassName variable = new ClassName(arguments);

Example:

Player p = new Player("Taylor", 7);

What Happens When new Runs

When Java executes that line:

  1. Memory is allocated for the object.
  2. The constructor runs.
  3. The constructor initializes instance variables.
  4. The reference is returned and stored in p.
  5. Execution continues after the line.

The constructor temporarily interrupts normal flow, runs its body, then control returns right after the call.

If you forget new:

Player p = Player("Taylor", 7); // compile error

Java thinks you’re calling a method, not creating an object.

Parameter Matching and Call by Value

Arguments must match:

  • Same number
  • Same types
  • Same order

Java uses call by value:

  • The constructor parameters receive copies of the argument values.
  • Changing the parameter inside the constructor does not change the original variable.

That detail sometimes appears in tricky tracing questions.

How Constructors Initialize Object State

Constructors usually assign parameters to instance variables.

public Player(String n, int s) {
    name = n;
    score = s;
}

Each object gets:

  • Its own copy of instance variables
  • Access to the same shared methods

If you create two objects:

Player a = new Player("A", 3);
Player b = new Player("B", 8);

They have separate name and score values. Changing a does not affect b.

This independence is critical in FRQ2. If your constructor fails to initialize variables properly, the rest of your class logic breaks.

How This Shows Up on Tests

You’ll commonly see:

  • “Which constructor is called?”
  • “Which line compiles?”
  • “What is the state of the object after this code runs?”
  • “Do these variables refer to the same object?”

On class-design FRQs:

  • You must initialize all required instance variables.
  • If the prompt gives sample objects, use them to reverse-engineer what the constructor should do.

Most constructor errors on quizzes come from mixing up parameter order or forgetting that the signature depends on types, not parameter names.

Key Takeaways

A constructor has the same name as the class and no return type.
Constructor signature depends only on name and ordered parameter types.
Overloaded constructors must differ in parameter list, not just parameter names.
new allocates memory, runs the constructor, then returns a reference.
Object variables store references, not actual objects.
Assigning one reference variable to another does not create a new object.
Arguments must match constructor parameters exactly in number, type, and order.
Constructors are where object state is established, and mistakes there affect everything else.

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