1.

Write a short note on destructors.

Answer»

It is a special function used to release the memory space allocated by the object.

  • Name of the Destructor is similar to the class, which it belongs.
  • It does not have argument(s) and doesn’t return any value (no return type)
  • Destructor is preceded by ~ (tilde) sign.
    Following points should be kept in mind while defining and writing the syntax for the destructor:
  • A destructor function must be declared with the same name as that of the class too. which it belongs.
  • The first character of the destructor name must begin with a tilde (~).
  • A destructor function is declared with no return types specified (not even void).
  • A destructor function must have public access in the class declaration.

General Syntax of Destructors:
~ classname();
The above is the general syntax of a destructor. In the above, the symbol tilde ~ represents a destructor that precedes the name of the class.



Discussion

No Comment Found

Related InterviewSolutions