Back to the 2026 paper

Module 2: Arrays and Strings

20262m

A constructor is automatically invoked when:

(i) A method is called
(ii) A package is imported
(iii) An object is created
(iv) A class is inherited

Worked SolutionAI Assisted

Answer: (iii) An object is created

A constructor runs when an object is instantiated with new (or through another constructor). It initializes the new object's state. Constructors have the class name and no return type.

class Student {
    Student() { System.out.println("Created"); }
}
Student s = new Student(); // invokes constructor

Similar questions

AI LearningWeb Platform

Coursify — Personal AI Course Generator

Struggling with a difficult subject or concept? Turn any engineering topic into a structured course with interactive lessons, quizzes, and research-backed explanations.