ICSE Class 10 Computer Applications Question 11 of 19

Constructors — Question 11

Back to all questions
11
Question

Question 11

How are parameterized constructors different from non-parameterized constructors?

Answer
Parameterised constructorNon-parameterised constructor
Parameterised constructor receives parameters and uses them to initialise the object's member variables.Non-parameterised constructor does not accept parameters and initialises the object's member variables with default values.
Parameterised constructors need to be explicitly defined for the class. They are never created automatically by the compiler.Non-parameterised constructors are considered default constructors. If no constructor is explicitly defined, then the compiler automatically creates a non-parameterized constructor.
For example,
Test(int x, int y)
{
a = x;
b = y;
}
For example,
Test()
{
a = 10;
b = 5;
}