Destructors

Question 1
Give the output
#include
using namespace
class Base1
{
public:
~Base1()
{
cout<<"Base1's destructor"< };
class Base2
{
public:
~Base1()
{
cout<<"Base2's destructor"< };
class Derived : public Base1,public Base2
{
public:
~Derived()
{
cout<<"Derived's destructor"< }
int main()
{
Derived d;
return 0;
}
A
Base1'1 destructor
Base2'2 destructor
Derived Destructor
B
Derived Destructor
Base2'2 destructor
Base1'1 destructor
C
Derived Destructor
D
Compiler Dependent
       OOPS       Destructors       Nielit Scientist-B IT 22-07-2017
Question 1 Explanation: 
● C++ constructor call order will be from top to down that is from base class to derived class and c++ destructor call order will be in reverse order.
● First child class and later parent class.
Question 2
In which case it is mandatory to provide a destructor in a class?
A
Almost in every class
B
Class for which two or more than two objects will be created
C
Class for which copy constructor
D
Class whose objects will be created dynamically
       OOPS       Destructors       KVS 22-12-2018 Part-B
Question 2 Explanation: 
→ Destructors are used to de-allocate the memory that has been allocated for the object by the constructor.
→ Unlike constructor a destructor neither takes any arguments nor does it returns value. And destructor can’t be overloaded.
There are 2 questions to complete.
PHP Code Snippets Powered By : XYZScripts.com
error: Content is protected !!