Object creation, or instantiation, is how you turn a class into a real object you can use. You use the new keyword followed by a constructor call, like new Student("Sarah", 16), and Java creates the object and stores a reference to it in a variable. For AP Computer Science A, focus on the constructor signature, the argument order, and what the reference variable stores.
Why This Matters for the AP Computer Science A Exam
Instantiation shows up across the AP Computer Science A exam because almost every program creates objects before using them. In the multiple-choice section, you will trace code, decide which constructor gets called based on its signature, and predict what happens when arguments do or do not match. In free-response code writing, you will declare reference variables and create objects with new to set up the data your algorithms work on. Getting comfortable with constructors now pays off later when you design your own classes and store objects in arrays and ArrayLists.

Key Takeaways
- A constructor has the same name as its class and runs when you create an object with
new. - A constructor signature is the constructor name plus the ordered list of parameter types, and that signature decides which constructor is called.
- Constructors can be overloaded: one class can have several constructors as long as their signatures differ.
- Create objects with
new ClassName(arguments), and the arguments must be compatible in order and number with a constructor's parameter list. - Arguments are passed by call by value, meaning the parameters get copies of the argument values.
- A reference variable holds a reference to an object, or
nullif it is not currently pointing to any object.
Objects and Classes: The Blueprint Relationship
A class is like a blueprint, and an object is a specific thing built from that blueprint. The class defines what attributes an object will have and what it can do. The object is the actual instance with its own values stored in memory.
When you write Student sarah = new Student("Sarah", 16);, you use the Student class to build an actual Student object. Every Student object shares the same set of attributes defined by the class, but each one holds its own values, like a different name and age.
The new Keyword and Object Creation
You create an object using the keyword new followed by a call to one of the class's constructors. The constructor has the same name as the class and is responsible for setting up the object's initial state.
When a constructor call runs, it interrupts the normal top-to-bottom flow of statements. The program executes the statements inside the constructor first, and once the constructor finishes, control returns to the point right after where you called it. The parameters in the constructor let it accept values that establish the initial values of the object's attributes.
</>Java// Example: Student class with a constructor public class Student { // Attributes - each object gets its own values private String name; private int age; private double gpa; // Constructor - runs when new Student(...) is used public Student(String studentName, int studentAge) { name = studentName; age = studentAge; gpa = 0.0; // starting value for new students } public String getName() { return name; } public void setGPA(double newGPA) { gpa = newGPA; } } // Creating objects Student sarah = new Student("Sarah", 16); Student michael = new Student("Michael", 17); // Each object holds its own data sarah.setGPA(3.8); michael.setGPA(3.2); // changing sarah's GPA does not affect michael's GPA
Constructor Signatures and Overloading
Java decides which constructor to call by looking at the constructor signature, which is the constructor's name plus the ordered list of parameter types. For new Student("Sarah", 16), Java looks for a Student constructor that takes a String and then an int, in that order.
A class can have more than one constructor as long as each has a different signature. This is called constructor overloading. It lets you create objects in different ways depending on what information you have.
</>Java// Example: multiple constructors with different signatures public class BankAccount { private String accountHolder; private double balance; private String accountType; // Name and initial deposit public BankAccount(String name, double initialDeposit) { accountHolder = name; balance = initialDeposit; accountType = "Checking"; } // Name, initial deposit, and account type public BankAccount(String name, double initialDeposit, String type) { accountHolder = name; balance = initialDeposit; accountType = type; } // Name only, starting with a zero balance public BankAccount(String name) { accountHolder = name; balance = 0.0; accountType = "Checking"; } } // Java picks the constructor whose signature matches the arguments BankAccount account1 = new BankAccount("Alice", 500.0); BankAccount account2 = new BankAccount("Bob", 1000.0, "Savings"); BankAccount account3 = new BankAccount("Charlie");
Constructor Arguments and Call by Value
A constructor argument is a value you pass into the constructor when you call it. The arguments must be compatible in order and number with the parameter types in the constructor's signature. If the types, order, or count do not match a constructor, the code will not compile.
Arguments are passed using call by value. That means the constructor's parameters are initialized with copies of the argument values you passed in. The constructor works with those copies to set up the object.
Reference Variables and null
A variable of a reference type does not hold the object itself. It holds a reference to the object, which you can think of as the location of that object in memory. If a reference variable is not currently pointing to an object, it holds the special value null.
</>Java// Example: reference variables and shared objects public class Car { private String make; private String model; private int year; public Car(String carMake, String carModel, int carYear) { make = carMake; model = carModel; year = carYear; } public String getInfo() { return year + " " + make + " " + model; } } Car car1 = new Car("Toyota", "Camry", 2022); Car car2 = new Car("Honda", "Civic", 2023); Car car3 = car1; // car3 refers to the SAME object as car1 System.out.println(car1.getInfo()); // 2022 Toyota Camry System.out.println(car3.getInfo()); // 2022 Toyota Camry (same object) System.out.println(car2.getInfo()); // 2023 Honda Civic (different object)
Notice that car3 = car1 does not build a new object. Both variables point to the same object, so using either one reaches the same data. To get a separate object, you have to call new again.
How to Use This on the AP Computer Science A Exam
MCQ
- Check the parameter types and order before deciding if a
newstatement compiles.new Student("Sarah", 16)needs a(String, int)constructor, andnew Student(16, "Sarah")would need a different one. - When a class lists several overloaded constructors, match the arguments to the one signature that fits in order, number, and type.
- Watch for reference questions where two variables point to the same object. A change through one variable shows up through the other.
Code Tracing
- When a constructor is called, trace into the constructor body, run its statements to set up the attributes, then return to the line right after the call.
- Track what each reference variable points to. A variable can hold an object reference or
null.
Free Response
- Declare reference variables with the correct type and use
newto create the objects your algorithm needs. - Pass arguments that match a constructor's parameter list so the object starts with the right values.
Common Trap
- Leaving out
newturns object creation into something Java reads as a method call, which will not compile. - Assigning one reference to another (
b = a) shares one object instead of copying it.
Common Misconceptions
- Creating an object without
newdoes not work.Student s = Student("Sarah", 16);is read as a method call, not object creation. - Assigning one reference variable to another does not make a second object. Both names refer to the same object until you use
newagain. - A reference variable does not store the object itself. It stores a reference to where the object lives in memory, or
nullif it points to nothing. - The constructor name is not arbitrary. It must match the class name exactly, and the signature is what Java uses to pick which constructor runs.
- Argument order matters. Even if the types could fit in another arrangement, the arguments must line up in the same order as the parameter list.
Related AP Computer Science A Guides
Vocabulary
The following words are mentioned explicitly in the College Board Course and Exam Description for this topic.Term | Definition |
|---|---|
call by value | A method of passing arguments where the parameters are initialized with copies of the argument values rather than references to the original values. |
constructor | A special method that is called to create and initialize an object of a class, having the same name as the class. |
constructor argument | A value passed to a constructor when it is called that must match the type, order, and number of parameters in the constructor signature. |
constructor signature | The combination of a constructor's name (same as the class name) and its ordered list of parameter types that uniquely identifies the constructor. |
flow of control | The order in which statements in a program are executed, which can be interrupted by method calls and resumed after the method completes. |
new | A Java keyword used to create a new instance of a class by allocating memory and calling the constructor. |
null | A special value indicating that a reference variable does not currently reference any object. |
object | A specific instance of a class with defined attributes and behaviors. |
object reference | A value that points to the memory location where an object is stored, allowing access to that object. |
overloaded constructor | Multiple constructors in the same class that have different signatures, allowing objects to be created with different sets of parameters. |
parameter | A variable declared in the header of a method or constructor that receives values passed to the method when it is called. |
parameter types | The data types of the values that are passed to a constructor or method. |
reference type | A data type that holds a reference (memory address) to an object rather than storing the object's value directly. |
variable | A named storage location in a program that holds a value of a specific data type; the value can change while the program is running. |
Frequently Asked Questions
How do you create an object in Java?
Create an object with the keyword new followed by a constructor call, such as new Student("Ava", 16). The constructor initializes the new object.
What is a constructor signature?
A constructor signature is the constructor name, which matches the class name, plus the ordered list of parameter types. Java uses the signature to decide which constructor is called.
What does constructor overloading mean?
Constructor overloading means a class has multiple constructors with different signatures. The arguments in a constructor call determine which one runs.
What does a reference variable store?
A reference variable stores an object reference, not the object itself. If it does not currently refer to an object, it stores null.
What does call by value mean for constructor arguments?
Call by value means constructor parameters receive copies of the argument values. The constructor uses those copies to initialize or work with the new object.
Why does assigning one object reference to another not create a new object?
An assignment like b = a copies the reference, so both variables refer to the same object. To create a separate object, call a constructor with new.