Lesson 1.13: Object Creation and Storage (Instantiation) | AP CSA
Lesson 1.13: Object Creation and Storage (Instantiation)
What you'll learn in this lesson
- 1.13.A. Identify the correct constructor being called based on its signature, including overloaded constructors.
-
1.13.B. Declare variables of the correct types to hold object references, including using
null. -
1.13.C. Create objects using
new, pass constructor arguments (call-by-value), and explain how execution flow interrupts for the constructor body.
This lesson is part of the AP CSA Course and Exam Description (effective May 2027).
AP exam weight: Instantiation appears in nearly every FRQ. You must write new ClassName(args) with correct argument types and order. See the Oracle Java tutorial on constructors for further reading.
Constructors: creating objects with new
A constructor has the same name as the class, no return type, and is called with new to create and initialize an object.
Instantiation Pattern
ClassName variable = new ClassName(arguments);
new allocates heap memory. The constructor initializes attributes. The reference is stored in variable.
Constructor signatures and overloading
Constructor Signature = Name + Parameter Types
Box() // no-arg constructor Box(int size) // one-arg constructor: overloaded
Arguments must match parameters in number, order, and compatible type. Call-by-value applies — parameters get copies.
AP Trap: execution flow through constructor
When new is called, execution jumps into the constructor body. The calling code pauses until the constructor completes, then the new object reference is returned.
AP Trap: null vs object
Box b = null; holds no object. Calling b.size throws NullPointerException at run time.
Practice Questions
Scanner to read from the keyboard?Scanner sc = Scanner(System.in);
Scanner sc = System.in;
sc = new Scanner(System.in);
Scanner sc = new Scanner(System.in);
Item() and Item(int value). Which call invokes the no-arg constructor?new Item(0)
new Item()
new Item(null)
Item()
Point(int x, int y). Which call causes a compile error?new Point(3.0, 4.0)
new Point(3, 4)
new Point(3, (int) 4.9)
new Point(-1, 0)
Box a = new Box(10); Box b = a; a.size = 99; System.out.println(b.size);
I. A constructor has the same name as the class.
II. A constructor must have return type
void.III. Constructors can be overloaded.
new ClassName(args) is called, which describes execution flow?Box box = new Box(5); resize(box, 20); System.out.println(box.size);
Dog variable that intentionally holds no object?Dog d = new Dog();
Dog d = 0;
Dog d = null;
Dog d = "";
Output Predictor — Object Creation
Predict the exact output. Tap below if you need the class.
Bug Hunt — Instantiation
Each snippet has exactly one buggy line. Click it, then submit.
The Bank Account
Assume:
class BankAccount {
String owner;
double balance;
BankAccount(String name, double amount) {
owner = name; balance = amount;
}
BankAccount(String name) {
owner = name; balance = 0.0;
}
}
Part A
new BankAccount("Alice")?Part B
b2.balance hold after this code?BankAccount b1 = new BankAccount("Bob", 500.0);
BankAccount b2 = b1;
b1.balance = 750.0;
Part C: Structured response
Write a third overloaded no-arg constructor for BankAccount that sets owner to "Unknown" and balance to 0.0. Then explain why three constructors with the same name are allowed.
Scoring Rubric (4 points)
-
+1: Correct constructor:
BankAccount() { owner = "Unknown"; balance = 0.0; } - +1: No return type in header.
- +1: Explains overloading: all three share the same name but have different signatures: (), (String), (String, double).
- +1: Notes Java selects the correct version based on argument types/count at the call site.
The this keyword in constructors
Inside a constructor, this refers to the object being created. When a parameter has the same name as an instance variable, this.name = name disambiguates: this.name is the field; name is the parameter. You will use this pattern extensively in Unit 3.
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]