-
What is the output of this program?
#include <iostream>
using namespace std;
class ParentClass
{
public:
ParentClass(void)
{
cout << "Parent()\n";
}
ParentClass(int k)
{
cout << "Parent("<< k << ")\n";
};
ParentClass(void)
{
cout << "~Parent()\n";
};
};
class ChildClass1 : public ParentClass{ };
class ChildClass2 : public ParentClass
{
public:
ChildClass2 (void)
{
cout << "Child2()\n";
}
ChildClass2 (int k) : ParentClass(k)
{
cout << "Child2(" << k << ")\n";
}
~ChildClass2 (void)
{
cout << "~Child2()\n";
}
};
int main (void)
{
ChildClass1 obj1;
ChildClass2 obj2;
ChildClass2 obj3(69);
return 0;
}
-
- Compilation Error
- Runtime Error
- Garbage value
- ParentClass()
ParentClass()
ChildClass2()
ParentClass(69)
ChildClass2(69)
~ChildClass2()
~ParentClass()
~Child2Class()
~ParentClass()
~ParentClass() - None of these
Correct Option: A
In this program, We got an error in overloading because we didn’t invoke the destructor of parent.