Explain parameterized constructors with example.
A constructor that can take arguments is known as parameterized constructor. In some applications, it may be necessary to initialize the various data members of different objects with different values when they are created. So parameterized constructor is used to achieve this by passing arguments to the constructor function when the objects are created.
Example:
class ABC
{
int m;
public:
ABC(int x) //parameterized constructor
{
m=x;
}
void put()
{
cout<<m;
}
};
void main()
{
ABC obj(10); // call to parameterized constructor
obj.put();
}