Java

Java Constructors Explained: Types, Overloading, ICSE

Default, parameterised, copy, overloading, and the constructor-vs-method comparison the paper loves, every example compiled and run.

Modern Age Coders
Modern Age Coders July 4, 2026
8 min read
Java constructors explained with types, overloading, and ICSE board examples

Every ICSE paper finds a way to ask about constructors, a definition here, an output question there, a design a class with... program almost every year. And every year, students who could write the code stumble on the ideas: what exactly runs when, why there is no return type, and what this is doing in there. This guide settles all of it, with every example compiled and executed.

The one-line version first: a constructor is the method-like block that runs automatically, exactly once, at the moment an object is born, and its whole job is to give that object its starting values. Everything else in the topic is detail on top of that sentence.

The Anatomy: What Makes a Constructor a Constructor

Two rules identify a constructor on sight, and both are exam questions in disguise: its name is exactly the class name, and it declares no return type, not even void. Break either rule and Java treats it as an ordinary method.

Anatomy of a Java constructor: same name as the class, no return type, runs automatically when new creates the object
Class name, no return type, triggered by new. Those three facts answer half the theory questions ever set.

Your first constructor, watched in action

The print statement inside the constructor is there as proof: watch it fire once per object, automatically, before anything else touches the object.

public class FirstCtor {
    String name;
    int marks;

    FirstCtor(String n, int m) {      // the constructor
        name = n;
        marks = m;
        System.out.println("Constructor ran for " + name);
    }

    public static void main(String[] args) {
        FirstCtor s1 = new FirstCtor("Asha", 92);
        FirstCtor s2 = new FirstCtor("Rohan", 85);
        System.out.println(s1.name + ": " + s1.marks);
        System.out.println(s2.name + ": " + s2.marks);
    }
}
Constructor ran for Asha
Constructor ran for Rohan
Asha: 92
Rohan: 85

Two objects, two automatic runs, each stamping its own object's data. Nobody called the constructor by name; new did it.

The Default Constructor

A constructor with no parameters is called a default constructor. It hands every new object the same sensible starting state. One fact examiners love: if you write NO constructor at all, Java quietly supplies an invisible no-argument one, but the moment you write any constructor yourself, that free one disappears.

public class DefaultCtor {
    String name;
    int marks;

    DefaultCtor() {                    // default constructor, no parameters
        name = "Not set";
        marks = 0;
    }

    public static void main(String[] args) {
        DefaultCtor s = new DefaultCtor();
        System.out.println(s.name + " / " + s.marks);
    }
}
Not set / 0

Parameterised Constructors and this

When constructor parameters use the same names as the fields, Java needs to know which name means which. this.name always means the object's field; plain name means the nearest parameter. This is the tidiest way to write constructors, and the syllabus expects you to read it fluently.

public class ThisDemo {
    String name;
    int marks;

    ThisDemo(String name, int marks) {
        this.name = name;      // this.name is the field, name is the parameter
        this.marks = marks;
    }

    public static void main(String[] args) {
        ThisDemo s = new ThisDemo("Meera", 96);
        System.out.println(s.name + " scored " + s.marks);
    }
}
Meera scored 96

Constructor Overloading

A class can hold several constructors as long as their parameter lists differ. Java picks the version that matches the arguments you pass to new. This is constructor overloading, and it is the single most-asked constructor concept in ICSE program questions.

Three constructors, one class

public class OverloadCtor {
    String name;
    int marks;

    OverloadCtor() {                      // version 1: no details yet
        name = "Unknown";
        marks = 0;
    }
    OverloadCtor(String n) {              // version 2: name only
        name = n;
        marks = 0;
    }
    OverloadCtor(String n, int m) {       // version 3: everything
        name = n;
        marks = m;
    }

    void display() {
        System.out.println(name + " -> " + marks);
    }

    public static void main(String[] args) {
        new OverloadCtor().display();
        new OverloadCtor("Asha").display();
        new OverloadCtor("Rohan", 85).display();
    }
}
Unknown -> 0
Asha -> 0
Rohan -> 85

Same class, three doorways in. Count the arguments in each new and you can predict which constructor fired, which is exactly the skill output questions test.

Constructor overloading in Java: new with zero, one, or two arguments dispatches to the matching constructor
Java matches new to a constructor by counting and typing the arguments. No match, no compile.

The Copy Constructor

A copy constructor takes an existing object and builds a new one with the same values. The proof that it truly copied is in the output: changing the duplicate leaves the original untouched.

public class CopyCtor {
    String name;
    int marks;

    CopyCtor(String n, int m) {
        name = n;
        marks = m;
    }
    CopyCtor(CopyCtor other) {            // copy constructor
        name = other.name;
        marks = other.marks;
    }

    public static void main(String[] args) {
        CopyCtor original = new CopyCtor("Zoya", 78);
        CopyCtor duplicate = new CopyCtor(original);
        duplicate.marks = duplicate.marks + 5;   // only the copy changes
        System.out.println("Original : " + original.name + " " + original.marks);
        System.out.println("Duplicate: " + duplicate.name + " " + duplicate.marks);
    }
}
Original : Zoya 78
Duplicate: Zoya 83

Constructor vs Method: The Comparison the Paper Loves

The differences fit in one program. The constructor carries the class name, has no return type, and ran exactly once, at new. The method has its own name, declares a return type, and ran every time we called it.

public class CtorVsMethod {
    int balance;

    CtorVsMethod(int start) {         // constructor: class name, no return type
        balance = start;
    }

    int deposit(int amount) {         // method: own name, has a return type
        balance = balance + amount;
        return balance;
    }

    public static void main(String[] args) {
        CtorVsMethod acc = new CtorVsMethod(100);   // constructor runs once, here
        System.out.println(acc.deposit(50));         // methods run whenever called
        System.out.println(acc.deposit(25));
    }
}
150
175
Constructor versus method in Java: name, return type, when it runs, and how many times
Four rows that appear in some form on nearly every paper. Learn them as a pair.

A Board-Style Program, Start to Finish

Here is the shape ICSE actually asks: design a class with fields, a parameterised constructor, a computing method, and a display method, then create objects and use them.

public class BoardStyle {
    String name;
    int price, quantity;

    BoardStyle(String n, int p, int q) {
        name = n;
        price = p;
        quantity = q;
    }

    int totalCost() {
        return price * quantity;
    }

    void display() {
        System.out.println(name + " x" + quantity + " = Rs " + totalCost());
    }

    public static void main(String[] args) {
        BoardStyle item1 = new BoardStyle("Notebook", 60, 3);
        BoardStyle item2 = new BoardStyle("Geometry box", 120, 1);
        item1.display();
        item2.display();
    }
}
Notebook x3 = Rs 180
Geometry box x1 = Rs 120

Fields, constructor, method, display, objects. Whatever story the question wraps around it, a shop, a library, a bank, this five-part skeleton is the answer.

The Mistakes That Cost Constructor Marks

  • Giving the constructor a return type: void ClassName() compiles, but it is now a method, and new will not call it. The paper sets this trap deliberately.
  • Misspelling the class name: a constructor named student inside class Student is just an unknown method. Case matters.
  • Expecting the free default constructor after writing your own: once any constructor exists, new ClassName() fails unless you wrote the no-argument version too.
  • Forgetting this with same-named parameters: name = name; assigns the parameter to itself and the field stays empty.
  • Calling a constructor like a method: obj.ClassName() is not a thing. Constructors run through new, once, at birth.
๐Ÿ’ก

The output-question shortcut

When a constructor question shows code and asks for output, first mark every new, then match each to its constructor by argument count. The printed lines follow that mapping in order. Two minutes, full marks.


Frequently Asked Questions

A special block with the same name as its class and no return type, which runs automatically when an object is created with new. Its job is initialisation: giving the new object its starting values.

The ones school syllabi test: the default (no-argument) constructor, the parameterised constructor, and the copy constructor which builds a new object from an existing one. Overloading lets one class offer several of these side by side.

Because its output IS the object being constructed; there is nothing separate to return. Writing a return type, even void, turns it into an ordinary method, which is a favourite trick in board theory questions.

Defining several constructors in one class with different parameter lists. Java selects the matching one by the number and types of arguments passed to new. It lets a class be created from full details, partial details, or none.

this refers to the object being built. Its main use is separating fields from same-named parameters: this.name = name; copies the parameter into the field. Without this, the parameter would just be assigned to itself.

Java supplies an invisible default constructor that takes no arguments, so new ClassName() still works. But the moment you define any constructor of your own, that automatic one is withdrawn.

Name: constructor matches the class, a method has its own. Return type: constructor has none, a method must declare one. Trigger: constructor runs via new, a method via a call. Frequency: once per object versus as often as you like.

One Idea, Fully Owned

Constructors are a small topic that examiners can slice many ways, and you have now seen every slice run for real: default, parameterised, this, overloading, copy, and the versus-method comparison. Put it to work inside the 50-program ICSE bank, where the constructor family closes the set, and see the same idea in Python in our OOP tutorial.

For the version of this topic where a teacher reads your class designs live, our ICSE Java classes are built for it, part of courses serving learners aged 6 to 67.

Related reading

Modern Age Coders

About Modern Age Coders

Expert educators passionate about making coding accessible and fun for learners of all ages.

Ask Misti AI
Chat with us