English
Tamil Nadu Board of Secondary EducationHSC Science Class 11

Mention the differences between constructor and destructor.

Advertisements
Advertisements

Question

Mention the differences between constructor and destructor.

Distinguish Between
Advertisements

Solution

Constructor:

  • The name of the constructor must be the same as that of the class.
  • No return type can be specified for the constructor.
  • A constructor can have a parameter list.
  • The constructor function can be overloaded.
  • They cannot be inherited but a derived class can call the base class constructor.
  • The compiler generates a constructor, in the absence of a user-defined constructor.

Destructor:

  • The destructor has the same name as that of the class prefixed by the tilde character
  • It has no return type.
  • The destructor cannot have arguments
  • Destructors cannot be overloaded i.e., there can be only one destructor in a class.
  • They cannot be inherited.
  • In the absence of a user-defined destructor, it is generated by the compiler.
shaalaa.com
  Is there an error in this question or solution?
Chapter 14: Classes and objects - Evaluation - Section - D [Page 247]

APPEARS IN

Samacheer Kalvi Computer Science [English] Class 11 TN Board
Chapter 14 Classes and objects
Evaluation - Section - D | Q 1. | Page 247
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×