1.

What is a parameterized constructor? How is it useful?

Answer»

A constructor that accepts parameters for its invocation is known as parameterized constructor. This helps you to assign initial value to an object at the time of its creation. For example,

class Test {

int ant; 

public:

Test(int i) // constructor with argument

{ ant = i;

}

 };

int main()

Test ob1(45); //argument value provided

}

}



Discussion

No Comment Found

Related InterviewSolutions