Default contructor

Default contructor:

A constructor with doesn’t  parameter is refers to as a default constructor is only called if an object definition doesn’t explicitly initialize the object. A default constructor will use standard value for all data members. If a class doesn’t contain a constructor definition a complier will create a minimal version of the default constructor as a public member.

Syntax:

Class_name()
{
contructor definition
}

Example

#include<iostream.h>

class dconstrucor

{

public: int a; int b;

dconstrucor()

{a=b=0;}

};

int main()

{

dconstrucor dc;

cout<<“values for default constructor a & b ::”<<dc.a<<“,”<<dc.b<<“\n”;

return 0;

}

Outout

values for default constructor a & b ::0,0.

Leave a Reply

Your email address will not be published. Required fields are marked *