1.

Mention the differences between constructor and destructor.

Answer»

Constructor:

  • The name of the constructor must be same as that of the class.
  • No return type can be specified for constructor.
  • A constructor can have 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 user defined destructor, it is generated by the compiler.


Discussion

No Comment Found