OOAD Functions Q/A #7


Question:Differentiate between constructor and destructor.

Answer:

Sr. No.ConstructorDestructor
1A constructor is used to initialize the object.A destructor is used to destroy the objects.
2A constructor can take arguments. Destructor carries no arguments.
3Constructors are called automatically when the objects are created.Destructors are called automatically when the objects are destroyed.
4A 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.
5A constructor can not be declared as virtual.Destructor can be virtual.
6A constructor being member functions can be overloaded.Destructor cannot be overloaded.
Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements