ICSE Class 10 Computer Applications Question 2 of 19

Constructors — Question 2

Back to all questions
2
Question

Question 2

If the constructor is automatically generated by the compiler, why do you need to define your own constructor?

Answer

A default constructor does not have any statement inside it. It initializes default values to the instance variables.

If we define our own constructor in a class, we can initialise the instance variables according to our requirements. A parameterised constructor allows the programmer to initialise objects with different values. This is achieved by passing the required values as arguments to the constructor method.

Get the Bright Tutorials app Stuck on a question? Ask Bright Buddy — your AI tutor — for step-by-step help in the app.