Thursday, May 7, 2009

Default Constructor

A Constructor without an argument is called default constructor

Syntax:

public:

constructor_name() // Class name

{

statements;

}

Example:

public:

num();

{

a=100;

b=200;

}



Example program for Default constructor

header files

class num

{

int a,b;

public:

num() // default constructor

{

a=100;

b=200;

}

void display()

};

void num::display()

{

cout<<>

cout<<>

}

void main()

{

num obj;

obj.display();

}

Output will be

100

200



No comments:

Post a Comment