Reference no: EM133985104
Question
1. The constructors are special type of functions which are called whenever an object is created. This is to initialize the data members of the class. The constructor allocates memory space for all the data members
2. The Destructors are special functions which are called just before an object is destroyed. This functions is responsible to free all the allocated resources to the object. Objects are destroyed whenever those go out of scope.
3. The constructors must contain only the class name. The class name is followed by the blank parenthesis or we can have parameters if some values are to be passed.
4. The destructor must have same name as that of the corresponding class. The class name should be preceded by the tilde symbol (~).
5. First the constructor of parent class are called. The order in which the parent class constructors are called is same in the sequence of inheritance used.
6. The destructors are called in the reverse order as that of the constructors being called. This is done to ensure that all the resources are released in sequence. That is, the derived class destructors will be called first.
7. The destructors doesn't have any arguments. The destructors have to be called implicitly whenever an object goes out of scope. The user can't pass argument to the implicit call.
8. The destructors are usually called implicitly whenever an object goes out of scope. The destructors can also be called explicitly if required. The call must be made, implicitly or explicitly.
9. Destructor will be called only to free the resources allocated for an object. The resources are allocated only the constructor for an object is called.
10. The destructor must be public for explicit calls. If it is made private or protected then it won't be accessible outside the class. There is no restriction of definition the destructor outside the class.