हिंदी
तमिलनाडु बोर्ड ऑफ सेकेंडरी एज्युकेशनएचएससी विज्ञान कक्षा ११

Mention the differences between constructor and destructor.

Advertisements
Advertisements

प्रश्न

Mention the differences between constructor and destructor.

अंतर स्पष्ट करें
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 14: Classes and objects - Evaluation - Section - D [पृष्ठ २४७]

APPEARS IN

सामाचीर कलवी Computer Science [English] Class 11 TN Board
अध्याय 14 Classes and objects
Evaluation - Section - D | Q 1. | पृष्ठ २४७
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×