2. A Constructor is a member function of class
which initializes the objects of the class .
It is automatically called ,when the objects is
created.
Constructor have different from normal
functions.
It same as class name itself.
It don’t have a return type.
Its automatically called , when the objects is
created.
class name::function name
4. It is the constructor which doesn’t
take any arguments.
It has no parameters.
class name()
{
………
}
5. There are the constructor with parameters.
Using this constructor , we can provide different
values to data of different objects by passing the
value as arguments.
class cube()
{
public:
int side;
cube(int x)
{
side=x;
}
};
6. There are the special type of constructor
which takes on object as arguments and is
used to copy values of data members of one
objects into other objects.
7. A Destructor is a special member function that
works opposite to constructor.
Destructor are used to destroy or delete the objects.
class name()
{
……….
}
The destructor name should exactly mach with the
class name.
A Destructor is declared to begin with (~) –tilde
symbol.
A Destructor is automatically called when the
program execution is finished.