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:
- Fundamentals of constructors
- State initialization
- Constructor overloading
- Constructor chaining
- Inheritance and polymorphism
- Execution flow
- Access control and patterns
- Edge Cases and Modern Java
Take your time analyzing each code snippet, trace the execution path carefully, and solidify your core Java OOP skills.
Explanation:
A constructor is invoked when an object is created. It is primarily used to initialize the object’s state.
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?
Constructor executed
Saanvi
null
Saanvi
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.
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?
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.
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?
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.
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?
Parameterized constructor
John
Rahul
No-argument constructor
Rahul
John
No-argument constructor
John
John
Parameterized constructor
Rahul
Rahul
Parameterized constructor
John
Rahul
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.
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?
double constructor
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.
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?
Parameterized constructor
Smith
0
No-argument constructor
Smith
0
Smith
0
Smith
0
No-argument constructor
Smith
0
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.
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?
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.
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?
Person constructor
Student constructor
Student constructor
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.
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?
Person constructor
Student constructor
Student constructor
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.
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.
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?
Method
Constructor
Method
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.
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.
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.
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.
A superclass has only a private constructor, and a subclass attempts to extend that superclass.
Which statement is correct?
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.
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();
}
}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.
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?
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.
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?
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:
ParentandChildare only loaded when the JVM actually needs them. - Nothing in
main()referencesParentorChildbefore thenew 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:Childneeds to be loaded → butParentis its superclass, soParentloads 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 issuper(10), which callsParent(int).Parent(int)‘s first statement isthis(), redirecting toParent().- 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 afterthis()→ 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.
- Before its body runs,
Final order: 8 → 1 → 5 → 2 → 3 → 4 → 6 → 7
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.


