C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - Programs (Q.No. 8)
8.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{   
    public:
    BixBase()
    {
        cout<< "Base OK. "; 
    }
};
class BixDerived: public BixBase
{
    public:
    BixDerived()
    { 
        cout<< "Derived OK. "; 
    }
    ~BixDerived()
    { 
        cout<< "Derived DEL. "; 
    }
};
int main()
{
    BixBase    objB;
    BixDerived objD;
    objD.~BixDerived();
    return 0;
}
Base OK. Derived OK. Derived DEL.
Base OK. Base OK. Derived OK. Derived DEL.
Base OK. Derived OK. Derived DEL. Derived DEL.
Base OK. Base OK. Derived OK. Derived DEL. Derived DEL.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
13 comments Page 2 of 2.

Bittooo said:   1 decade ago
Can we call destructor from main function? is it possible?

Shrey said:   1 decade ago
The answer is correct .I compiled in Dev c++;

Anil said:   1 decade ago
Why derived del is displayed 2 times ?


Post your comments here:

Your comments will be displayed after verification.