KnowledgeBoat Logo
LoginJOIN NOW

Computer Applications

How are parameterized constructors different from non-parameterized constructors?

Java Constructors

15 Likes

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;
}

Answered By

10 Likes


Related Questions