01
Overview

Constructors: how new objects begin life.

A constructor is the special method that runs the moment new creates an object — and it sets the object's starting state.

A constructor is a special method whose job is to initialize a newly created object. It runs automatically when you write new ClassName(...), and it's where instance variables typically receive their starting values.

Constructors look like methods but have two distinctive rules: they have the same name as the class, and they have no return type (not even void).

On the AP exam, constructors appear in FRQ class design (always), in MCQs about signatures, and in tracing problems that ask what an object's state is right after creation.

02
Core Concept

Same name as the class, no return type.

A class can have multiple constructors with different parameter lists.

Parameterized constructor

public class Student {
    private String name;
    private int grade;

    public Student(String n, int g) {
        name = n;
        grade = g;
    }
}

This constructor takes two arguments and assigns them to the instance variables. Called with new Student("Ana", 11).

No-argument constructor

public Student() {
    name = "Unknown";
    grade = 9;
}

A constructor with no parameters lets clients create an object with sensible defaults: new Student().

The default constructor

If you write a class with no constructors, Java silently provides a free default constructor with no parameters that leaves fields at their default values. As soon as you write any constructor of your own, Java stops providing the default one.

Multiple constructors (overloading)

A class can have several constructors as long as each has a different parameter list. The compiler picks the matching one based on the arguments.

public Student(String n) {       // grade defaults to 9
    name = n;
    grade = 9;
}

public Student(String n, int g) {  // both provided
    name = n;
    grade = g;
}

Using this for clarity

When a parameter has the same name as a field, use this to reference the field:

public Student(String name, int grade) {
    this.name = name;
    this.grade = grade;
}
03
Key Vocabulary

Constructor terminology.

Used in nearly every class-design question.

Vocabulary
  • Constructor — special method that initializes a new object.
  • No-arg constructor — a constructor with no parameters.
  • Parameterized constructor — a constructor that takes one or more arguments.
  • Default constructor — the no-arg constructor Java provides automatically when you write none.
  • Constructor overloading — multiple constructors with different parameter lists.
  • this — keyword referring to the current object; used to disambiguate fields from parameters.
  • new — operator that allocates memory and invokes the constructor.
04
AP Exam Focus

How constructors are tested.

Signature exactness and field initialization dominate.

Exam Focus

What graders look for in a constructor FRQ:

  • Exact signature. Parameter types and order must match the prompt precisely.
  • All fields initialized. Every instance variable should be assigned a starting value.
  • No return type. Adding void turns the constructor into a regular method and breaks new.
  • No accidental shadowing. If parameter names match field names, use this.

MCQs ask which calls to new compile, given a class with several constructors — or what state an object has immediately after a constructor runs.

05
Worked Example

Spot the broken constructor.

A subtle shadowing bug leaves fields at default values.

Worked Example AP-style reasoning

Problem. What is printed?

public class Point {
    private int x;
    private int y;

    public Point(int x, int y) {
        int x_ = x;   // local variable, not the field
        int y_ = y;   // local variable, not the field
    }

    public int getX() { return x; }
    public int getY() { return y; }
}

Point p = new Point(3, 7);
System.out.println(p.getX() + " " + p.getY());

Step 1. The constructor receives x = 3, y = 7 as parameters.

Step 2. It creates two new local variables x_ and y_. These do not touch the fields.

Step 3. After the constructor returns, the fields x and y still hold their default values of 0.

Step 4. p.getX() returns 0, p.getY() returns 0.

Answer. The program prints 0 0.

The fix. Assign to the fields explicitly. Because the parameters share names with the fields, use this:

public Point(int x, int y) {
    this.x = x;
    this.y = y;
}

Why this matters. Field shadowing is one of the most common silent bugs in AP CSA constructors. The code compiles but produces wrong state.

06
Common Mistakes

Constructor errors that lose easy points.

Tiny syntax slips can disable an entire FRQ.

Watch Out
  • Adding a return type like public void Student(...). That's a regular method, not a constructor; new Student(...) won't use it.
  • Misspelling the class name in the constructor — it becomes a normal method.
  • Forgetting to assign parameters to fields. Fields stay at their defaults silently.
  • Shadowing fields with parameters. Use this.field = field to fix.
  • Losing the default constructor. Once you write any constructor, the implicit no-arg one disappears. new MyClass() stops compiling unless you add it explicitly.
  • Calling another constructor incorrectly. Inside one constructor, you can call another with this(args) — but only as the first statement.
07
Reference Table

Constructor rules at a glance.

A checklist for any constructor on the AP exam.

Constructors Reference

AP Quick Reference
Rule Meaning AP Exam Tip
Same name as class Required to be recognized as a constructor Match capitalization exactly.
No return type Not even void Adding one creates a regular method.
Called via new Cannot be called directly afterward new Class(args) is the only invocation.
Overloading allowed Multiple constructors with different parameter lists Java picks by argument types.
Default constructor Provided only if you write none Add one explicitly if needed.
this Refers to the current object Use when parameter and field share a name.
08
Practice Tip

How to write bulletproof constructors.

A short checklist beats trial-and-error.

Practice Strategy

Use the three practice tools below this lesson in order:

  • MCQ Practice — for every constructor call, identify which constructor matches the arguments. Eliminate options whose signatures don't compile.
  • Java Lab — write classes with multiple constructors. Verify that each constructor produces the correct starting state by printing the fields.
  • FRQ Practice — copy the constructor signature from the prompt character-by-character. Initialize every field. Use this when parameter names match field names.

If your constructor always passes the same three checks — right name, no return type, every field assigned — it will earn full credit.

09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

Topic Quiz 30 min 30 marks Pending

AP CSA Topic Practice: Constructors

AP-style topic practice assessment

Start
FRQ Practice 30 min 18 marks Pending

AP CSA Unit 03 Topic 03 Constructors FRQ Practice

AP-style topic practice assessment

Start