Thursday, September 23, 2010

Constructors:

Constructors are similar to functions which has function identifier similar to class identifier. It gets executed when a object came into existence,i.e., when a object is created. There are variety of constructors. They are:

1.Default constructors
2.Parametrized constructors
3.Copy constructors
4.Overloading constructors

Default constructors:
        Default constructor are constructors which has no parameters. Default constructor assign default value as 0 to its public, private and protected data members.

Syntax:
class class_name
{
//class definitions

class_name()
{}
}

Example:
class book
{
int a,b;
public:
book()
{
}
};
int main()
{
book b;
}

No comments:

Post a Comment