Java Constructor Quiz: 20 Questions (Basic to Advanced)

Welcome to this comprehensive Java constructor quiz! Here, we have compiled the top 20 multiple-choice questions (MCQs) from basic to advanced concepts of constructors. We have covered the following topics:

Take your time analyzing each code snippet, trace the execution path carefully, and solidify your core Java OOP skills.

What is the primary purpose of a constructor in Java?
A. To return a value after an object is created.
B. To initialize an object when it is created.
C. To destroy an object when it is no longer needed.
D. To define a method that can be called without creating an object.
To initialize an object when it is created.

Explanation:
A constructor is invoked when an object is created. It is primarily used to initialize the object’s state.

Consider the following Java code:
class Student {
    String name;
    Student() {
        name = "Saanvi";
        System.out.println("Constructor executed");
    }
}

public class Main {
    public static void main(String[] args) {
        Student student = new Student();
        System.out.println(student.name);
    }
}

What is the output?

A. Saanvi
Constructor executed
B. Constructor executed
Saanvi
C. Constructor executed
null
D. Saanvi
Constructor executed
Saanvi
Explanation:
The new Student() creates a Student object and immediately invokes the no-argument constructor. The constructor prints “Constructor executed” and assigns “Saanvi” to the variable name. The next statement prints student.name.
Consider the following Java code:
class Student {
    String name;
}
public class Main {
    public static void main(String[] args) {
        Student student = new Student();
        System.out.println(student.name);
    }
}

What happens when this program is compiled and executed?

A. It prints null.
B. It produces a compilation error because Student has no constructor.
C. It prints an empty string.
D. It throws a NullPointerException.
It prints null.
Explanation:
Since the Student class does not declare any constructor, Java implicitly provides a default constructor with no arguments. The name field is a reference variable, so its default value is null.
Consider the following Java code:
class Student {
    String name;
    Student(String name) {
        this.name = name;
    }
}
public class Main {
    public static void main(String[] args) {
        Student student = new Student();
        System.out.println(student.name);
    }
}

What happens when you compile this program?

A. It compiles successfully and student.name is null.
B. It compiles successfully and student.name is an empty string.
C. It results in a compilation error because Student() is not defined.
D. It compiles successfully because Java always provides a default constructor.
It results in a compilation error because Student() is not defined.
Explanation:
The class explicitly declares Student(String name). Therefore, Java does not automatically provide a no-argument constructor Student(). The statement new Student() has no matching constructor. Declaring a parameterized constructor prevents Java from automatically supplying a no-argument constructor.
Consider the following Java code:
class Student {
    String name;
    Student() {
        name = "John";
        System.out.println("No-argument constructor");
    }
    Student(String name) {
        this.name = name;
        System.out.println("Parameterized constructor");
    }
}
public class Main {
    public static void main(String[] args) {
        Student first = new Student();
        Student second = new Student("Rahul");

        System.out.println(first.name);
        System.out.println(second.name);
    }
}

What is the output?

A. No-argument constructor
Parameterized constructor
John
Rahul
B. Parameterized constructor
No-argument constructor
Rahul
John
C. No-argument constructor
No-argument constructor
John
John
D. Parameterized constructor
Parameterized constructor
Rahul
Rahul
No-argument constructor
Parameterized constructor
John
Rahul
Explanation:
The new Student() matches the no-argument constructor, while new Student(“Rahul”) matches the parameterized constructor. Each constructor initializes the corresponding object’s name.

Key concept: Java supports constructor overloading, meaning a class can have multiple constructors with different parameter lists. The compiler selects the appropriate constructor based on the arguments supplied during object creation.

Consider the following Java code:
class Student {
    Student(int id) {
        System.out.println("int constructor");
    }
    Student(double id) {
        System.out.println("double constructor");
    }
}
public class Main {
    public static void main(String[] args) {
        Student student = new Student(10);
    }
}

Which constructor is invoked, and what is the output?

A. double constructor
B. int constructor
C. int constructor
double constructor
D. The program produces a compilation error because both constructors have the same parameter name.
int constructor
Explanation:
The literal 10 has type int, which exactly matches the parameter type of Student(int id). Therefore, that constructor is selected.

Key concept: Constructor overloading is resolved primarily from the number, types, and order of parameters. An exact type match is preferred over a widening conversion.

Consider the following Java program:
class Student {
    String name;
    int age;
    Student() {
        this("Smith", 0);
        System.out.println("No-argument constructor");
    }
    Student(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("Parameterized constructor");
    }
}
public class Main {
    public static void main(String[] args) {
        Student student = new Student();
        System.out.println(student.name);
        System.out.println(student.age);
    }
}

What is the output?

A. No-argument constructor
Parameterized constructor
Smith
0
B. Parameterized constructor
No-argument constructor
Smith
0
C. No-argument constructor
Smith
0
D. Parameterized constructor
Smith
0
Parameterized constructor
No-argument constructor
Smith
0
Explanation:
The new Student() first enters the no-argument constructor. Its first statement, this(“Smith”, 0), invokes the parameterized constructor. After that constructor finishes, the execution returns to the no-argument constructor and prints “No-argument constructor”.

Key concept: this(…) is used for constructor chaining within the same class. A this(…) constructor call must be the first statement in the constructor.

A developer wants to reuse another constructor but writes the following code:
class Student {
    String name;
    Student() {
        System.out.println("Creating student");
        this("Mark");
    }
    Student(String name) {
        this.name = name;
    }
}

What happens when this code is compiled?

A. It compiles successfully and prints Creating student.
B. It compiles successfully, and the parameterized constructor executes first.
C. It produces a compilation error because this(“Mark”) must be the first statement in the constructor.
D. It produces a runtime error because constructors cannot call other constructors.
It produces a compilation error because this(“Mark”) must be the first statement in the constructor.
Explanation:
this(“Mark”) is an explicit constructor invocation. Java requires it to be the first statement in the constructor body.

Key concept: When using this(…) for constructor chaining, it must be the first statement of the constructor.

Consider the following Java program:
class Person {
    Person() {
        System.out.println("Person constructor");
    }
}
class Student extends Person {
    Student() {
        super();
        System.out.println("Student constructor");
    }
}
public class Main {
    public static void main(String[] args) {
        Student student = new Student();
    }
}

What is the output?

A. Student constructor
Person constructor
B. Person constructor
Student constructor
C. Student constructor
D. Person constructor
Person constructor
Student constructor
Explanation:
The super() explicitly invokes the no-argument constructor of the superclass, Person. After it completes, the execution continues in the Student constructor.

Key concept: In a subclass constructor, super() invokes a superclass constructor, and it must be the first statement when explicitly used. The superclass constructor executes before the subclass constructor body.

Consider the following Java program:
class Person {
    Person() {
        System.out.println("Person constructor");
    }
}
class Student extends Person {
    Student() {
        System.out.println("Student constructor");
    }
}
public class Main {
    public static void main(String[] args) {
        Student student = new Student();
    }
}

The Student() constructor does not explicitly call super(). What is the output?

A. Student constructor
Person constructor
B. Person constructor
Student constructor
C. Student constructor
D. The program produces a compilation error because every subclass constructor must explicitly call super().
Person constructor
Student constructor
Explanation:
When a constructor does not explicitly invoke another constructor, Java implicitly inserts a call to the superclass’s no-argument constructor (super()) as the first statement, provided that such a constructor is accessible. Therefore, Person() executes first.

Key concept: If a constructor does not explicitly invoke this(…) or super(…), Java implicitly inserts super() as its first statement. This works only when the superclass has an accessible no-argument constructor.

Which statement about Java constructors is correct?
A. Constructors are inherited by subclasses, just like methods.
B. A constructor can be declared static so that it can be called without creating an object.
C. A constructor must always be explicitly called using new from the main() method.
D. A constructor can have the same name as its class, but it cannot have a return type, including void.
A constructor can have the same name as its class, but it cannot have a return type, including void.
Explanation:
A constructor must have the same name as its class and must not declare a return type. This includes void. For example, Student() is a constructor, while void Student() is a method named Student, not a constructor.

Key concept: A constructor is fundamentally different from a method: it has the class name, has no return type, is not inherited, and is associated with object initialization.

Consider the following Java code:
class Student {
    void Student() {
        System.out.println("Method");
    }
    Student() {
        System.out.println("Constructor");
    }
}
public class Main {
    public static void main(String[] args) {
        Student student = new Student();
        student.Student();
    }
}

What will be the output of this program?

A. Constructor
Method
B. Method
Constructor
C. Constructor
D. The program produces a compilation error because a method cannot have the same name as its class.
Constructor
Method
Explanation:
The new Student() invokes the Student() constructor, which prints Constructor. Then, the student.Student() explicitly calls the void Student() method, which prints Method.

Key concept: Student() and void Student() are fundamentally different. The first is a constructor; the second is a method because it has a return type.

Which statement about constructor overloading in Java is correct?
A. Two constructors can have the same parameter list if their constructor bodies are different.
B. A class can have multiple constructors only if each constructor has a different name.
C. Constructor overloading is determined by the constructor’s return type.
D. Two constructors cannot have the same parameter list, even if their implementations are different.
Two constructors cannot have the same parameter list, even if their implementations are different.
Explanation:
A class can have multiple constructors, but their parameter lists must differ in number, types, or order of parameters.

Key concept: Constructor overloading is determined by the parameter list, not by the constructor body, parameter names, or return type.

Which statement correctly distinguishes constructor overloading from method overloading in Java?
A. Constructors can be overloaded by changing their return type, while methods can be overloaded by changing their parameter list.
B. Both constructors and methods can be overloaded by changing their parameter lists, but constructors do not have a return type.
C. Constructors cannot be overloaded, while methods can be overloaded.
D. Constructors are overloaded based on their names, while methods are overloaded based only on their return types.
Both constructors and methods can be overloaded by changing their parameter lists, but constructors do not have a return type.
Explanation:
Both constructors and methods support overloading through different parameter lists. The key distinction is that constructors have the class name and no return type, whereas methods have a method name and a declared return type (or void).

Key concept: For both constructors and methods, overloading is based on the parameter list, not the return type.

Which statement about access modifiers for Java constructors is correct?
A. A constructor must always be public so that objects of the class can be created.
B. A private constructor prevents code outside the class from directly creating objects using that constructor.
C. A constructor cannot be declared protected because constructors are never inherited.
D. A constructor with package-private access can be called from any class as long as the class itself is public.
A private constructor prevents code outside the class from directly creating objects using that constructor.
Explanation:
A private constructor can be invoked only from within the class itself. This is commonly used when a class controls how its objects are created, such as in certain utility or singleton-style designs.

Key concept: A constructor’s access modifier controls who can invoke it. Constructors themselves are not inherited, but their accessibility still matters for object creation and subclass construction.

Consider this situation:
A superclass has only a private constructor, and a subclass attempts to extend that superclass.
Which statement is correct?
A. The subclass can always call the private superclass constructor using super() because constructors are inherited.
B. The subclass can extend the superclass normally because Java automatically changes the private constructor to protected.
C. The subclass cannot directly invoke the superclass’s private constructor, so a normal subclass constructor cannot be compiled unless an accessible superclass constructor is available.
D. The subclass automatically receives a copy of the private superclass constructor.
The subclass cannot directly invoke the superclass’s private constructor, so a normal subclass constructor cannot be compiled unless an accessible superclass constructor is available.
Explanation:
Every subclass constructor must ultimately invoke a superclass constructor. If the superclass provides only a private constructor, the subclass cannot directly invoke it because it is inaccessible. Therefore, the subclass cannot be normally constructed unless the superclass provides some accessible constructor.

Key concept: A subclass constructor must invoke an accessible superclass constructor. A private superclass constructor cannot be directly invoked by a subclass.

Predict the output of the following code:
class Base {
    Base() {
        init();
    }
    void init() {
        System.out.println("Base init");
    }
}
class Derived extends Base {
    private int value = 10;
    @Override
    void init() {
        System.out.println("Derived init, value = " + value);
    }
}

public class Main {
    public static void main(String[] args) {
        new Derived();
    }
}
A. Base init
B. Derived init, value = 10
C. Derived init, value = 0
D. Compilation error
Derived init, value = 0
Explanation:
When new Derived() is called, Java first implicitly invokes Base(), which calls init(). Due to polymorphism, the overridden Derived.init() runs — but Derived’s field initializers (value = 10) haven’t executed yet, since they only run after the superclass constructor finishes. So value still holds its default int value, 0.
You’re creating a simple Student class for a school management system. Every student must have a name when they are registered — the system should not allow a student to exist without one.
public class Student {
    private String name;
    public Student(String name) {
        this.name = name;
    }
    public void display() {
        System.out.println("Student name: " + name);
    }
}

public class Main {
    public static void main(String[] args) {
        Student s = new Student("Aditi");
        s.display();
    }
}

What is the main purpose of the constructor in this scenario?

A. To display the student’s name on the screen.
B. To create a new class called Student.
C. To allow the program to run without any errors.
D. To ensure every Student object is created with a name already assigned, so no student exists without one.
To ensure every Student object is created with a name already assigned, so no student exists without one.
Explanation:
The constructor Student(String name) requires a name argument before an object can be created. This guarantees that every Student object starts life with a valid name already assigned — there’s no way to create a Student without one, since there’s no no-argument constructor available.
Study the following code carefully:
class Parent {
    static { System.out.println("1: Parent static block"); }
    { System.out.println("2: Parent instance block"); }

    Parent() {
        System.out.println("3: Parent constructor");
    }

    Parent(int x) {
        this();
        System.out.println("4: Parent constructor(int), x = " + x);
    }
}
class Child extends Parent {
    static { System.out.println("5: Child static block"); }
    { System.out.println("6: Child instance block"); }

    Child() {
        super(10);
        System.out.println("7: Child constructor");
    }
}
public class Main {
    public static void main(String[] args) {
        System.out.println("8: Before object creation");
        new Child();
    }
}

What is the correct output order?

A. 1, 5, 8, 2, 3, 4, 6, 7
B. 8, 1, 5, 2, 3, 4, 6, 7
C. 1, 5, 8, 3, 4, 2, 6, 7
D. 8, 1, 5, 3, 4, 6, 2, 7
1, 5, 8, 2, 3, 4, 6, 7

Explanation:

  • Static blocks run once, the first time a class is loaded — this happens when the class is first actively used, not automatically at program start.
  • Java uses lazy class loading: Parent and Child are only loaded when the JVM actually needs them.
  • Nothing in main() references Parent or Child before the new Child() line — so those classes aren’t loaded yet when “8: Before object creation” prints.
  • This means 8 prints first.
  • When new Child() executes, the JVM triggers class loading:
    • Child needs to be loaded → but Parent is its superclass, so Parent loads first.
    • Parent‘s static block runs → prints 1.
    • Child‘s static block runs next → prints 5.
  • With both classes now loaded, object construction begins:
    • Child()‘s first statement is super(10), which calls Parent(int).
    • Parent(int)‘s first statement is this(), redirecting to Parent().
    • Before Parent()‘s body runs, Parent‘s instance initializer block runs → prints 2.
    • Parent()‘s constructor body then runs → prints 3.
    • Control returns to Parent(int), which continues after this() → prints 4.
    • Control returns to Child():
      • Before its body runs, Child‘s instance initializer block runs → prints 6.
      • Child()‘s constructor body then runs → prints 7.

Final order: 8 → 1 → 5 → 2 → 3 → 4 → 6 → 7

Which of the following statements about Java constructors is true?
A. An abstract class cannot have a constructor, since it can never be instantiated directly.
B. If a class defines only a private constructor, it can never be instantiated — not even from within the same class.
C. A constructor can be abstract, final, or static, just like regular methods, to control how subclasses use it.
D. An abstract class can have a constructor, and that constructor runs whenever a concrete subclass object is created — even though the abstract class itself can never be instantiated directly.
An abstract class can have a constructor, and that constructor runs whenever a concrete subclass object is created — even though the abstract class itself can never be instantiated directly.
Explanation:
An abstract class is allowed to have a constructor, even though you can never directly create an object of that abstract class using new.Here’s the simple idea:

  • You can’t write new AbstractClass() — that’s not allowed.
  • But when you create an object of a subclass that extends the abstract class, Java still runs the abstract class’s constructor first.
  • This happens automatically (or you can trigger it yourself using super()).
  • So the constructor isn’t useless — it just never runs on its own. It only runs as part of creating a subclass object.

DEEPAK GUPTA

DEEPAK GUPTA

Deepak Gupta is the Founder of Scientech Easy, a Full Stack Developer, and a passionate coding educator with 8+ years of professional experience in Java, Python, web development, and core computer science subjects. With strong expertise in full-stack development, he provides hands-on training in programming languages and in-demand technologies at the Scientech Easy Institute, Dhanbad.

He regularly publishes in-depth tutorials, practical coding examples, and high-quality learning resources for both beginners and working professionals. Every article is carefully researched, technically reviewed, and regularly updated to ensure accuracy, clarity, and real-world relevance, helping learners build job-ready skills with confidence.