Interview Q&A / Object-Oriented Programming

BeginnerIn-depth3 min readUpdated 2 Oct 2026

What is a constructor, and what is constructor chaining?

SHORT ANSWER

A constructor is a special method with the class's name and no return type that runs when an object is created, to set its starting state. Constructor chaining is one constructor calling another, either in the same class with this(...) or in the parent class with super(...), so setup code is written once.

Explain it simply

A constructor is the admission desk of a college. Every new student passes through it once, and walks out with an ID number, a branch and a hostel room. Without it, you could end up with a "student" who has no roll number.

Constructor chaining is like a fast-track form that says "same as the regular form, but with hostel already set to No". Instead of repeating the whole admission process, the short form hands off to the full one. And before a student is admitted to the CSE department, they must first be admitted to the college itself. That parent step is super(...).

Example

java
class Person {
    protected final String name;

    Person(String name) {
        this.name = name;
        System.out.println("Person ready: " + name);
    }
}

class Student extends Person {
    private final String branch;
    private final boolean hosteller;

    Student(String name, String branch, boolean hosteller) {
        super(name);                       // parent first
        this.branch = branch;
        this.hosteller = hosteller;
        System.out.println("Student ready: " + branch + ", hostel=" + hosteller);
    }

    Student(String name, String branch) {
        this(name, branch, false);         // reuse the full constructor
    }

    Student(String name) {
        this(name, "Undeclared");
    }
}

public class Admission {
    public static void main(String[] args) {
        new Student("Riya");
        // prints: Person ready: Riya
        // prints: Student ready: Undeclared, hostel=false
    }
}

Student("Riya") calls Student("Riya", "Undeclared"), which calls the three-argument constructor, which first calls Person("Riya"). All the real setup lives in one place.

How it works

  • A constructor has the same name as the class and no return type, not even void. It can be overloaded.
  • If you write no constructor at all, Java adds a default constructor with no parameters. If you write any constructor, Java does not add one.
  • Every constructor starts by calling another constructor: either this(...) (same class) or super(...) (parent). If you write neither, the compiler inserts super() for you.
  • You can call this(...) or super(...), not both, in the same constructor.
  • Constructors run top-down: Object, then the parent, then the child. The parent part of the object is always ready before the child's code runs.
  • Constructors are not inherited, and they cannot be static, final or abstract.

Real-world use

  • Classes with sensible defaults: new ArrayList<>() and new ArrayList<>(100) both exist, and the simpler one fills in a default.
  • Entity classes where a short constructor fills in timestamps or status and chains to a full one.
  • Exception classes: a custom PaymentFailedException(String message) calls super(message) so the message reaches Throwable.

Common mistakes

  • Writing a parameterised constructor in the parent and then getting "constructor Person in class Person cannot be applied" in the child. The child's constructor implicitly calls super(), and that no-argument constructor no longer exists. Call super(name) explicitly.
  • Copy-pasting the same validation into every overloaded constructor instead of chaining.
  • Calling an overridable method from a constructor. The child's version runs before the child's fields are set, so it sees default values like null or 0.
  • Writing void Student(). That is a normal method, not a constructor.

What to say in the interview

"A constructor initialises a new object. It has the class's name, no return type, and can be overloaded. If I don't write one, Java gives a default no-argument constructor. Constructor chaining means one constructor calling another: this(...) calls another constructor in the same class, and super(...) calls the parent's. Every constructor calls one of them, and if I don't, the compiler inserts super(). So objects are built from the top of the hierarchy down, and chaining keeps setup logic in one place instead of repeating it."

Follow-up questions

  • Can a constructor be private? Why would you do that?
  • What happens if the parent class has no no-argument constructor?
  • Can a constructor call an overridden method? What goes wrong?
  • What is a copy constructor?

Go deeper

Read these once the basics above feel easy.

A private constructor stops other classes from creating objects directly. It is used in singletons, in utility classes like Math that should never be instantiated, and with static factory methods such as LocalDate.of(...), where the class controls creation. For a long time Java required this(...) or super(...) to be the very first statement. Java 25 finalised "flexible constructor bodies", which allows statements such as argument validation before that call, as long as they do not use the object being built. On older versions, put such checks inside a static helper method called within the argument list.

#oop#constructors#java#inheritance

Related questions

Practise more Object-Oriented Programming questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Object-Oriented Programming quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.