OOAD Functions Q/A #7



Question:Differentiate between constructor and destructor.

Answer:

Sr. No. Constructor Destructor
1 A constructor is used to initialize the object. A destructor is used to destroy the objects.
2 A constructor can take arguments. Destructor carries no arguments.
3 Constructors are called automatically when the objects are created. Destructors are called automatically when the objects are destroyed.
4 A constructor name should be the same as the class name. A destructor name must also be the same as the class name but proceeded by '>' sign.
5 A constructor can not be declared as virtual. Destructor can be virtual.
6 A constructor being member functions can be overloaded. Destructor cannot be overloaded.
Advertisements