What is parametrized constructor? Explain 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)
{
m=x;
}
void put()
{
cout<<m;
}
};
void main()
{
ABC obj(10);
obj.put();
}