retagged by
1,811 views
1 votes
1 votes

Give the output 

#include<iostream>
using namespace std;
class Base1{
public:
~Base1() {cout<<"Base1's destructor"<<endl;}
};
class Base2
{
public:
~Base2(){cout<<"Base2's destructor"<<endl;}
};
class Derived : public Base1,public Base2{
public:
~Derived(){cout<<"Derived's destructor"<<endl; }
};
int main()
{
Derived d;
return 0;
}
  1. Base$1$'s destructor
    Base$2$'s destructor
    Derived’s Destructor
  2. Derived’s Destructor
    Base$2$'s destructor
    Base$1$'s destructor
  3. Derived’s Destructor
  4. Compiler Dependent
retagged by

2 Answers

2 votes
2 votes

Answer: (B)

Base class constructors are called first and the derived class constructors are called next in single inheritance. Destructor is called in reverse sequence of constructor invocation, i.e., The destructor of the derived class is called first and the destructor of the base is called next.

0 votes
0 votes

Base class constructors are called first and the derived class constructors are called next in single inheritance. Destructor is called in reverse sequence of constructor invocation i.e. The destructor of the derived class is called first and the destructor of the base is called next.

Here its case of multiple inheritance

For multiple inheritance order of constructor call is, the base class’s constructors are called in the order of inheritance and then the derived class’s constructor.

So A is correct.

Ref: https://www.geeksforgeeks.org/order-constructor-destructor-call-c/

 

Answer:

Related questions

1.5k
views
2 answers
0 votes
admin asked Mar 30, 2020
1,545 views
Give the output #include<iostream> using namespace std; class Base { public: int x,y; public: Base(int i, int j){x=i;y=j;} }; class Derived:public Base { public: ... ); q.print(); return 0; }$10\:10$Compiler Error$0\:0$None of the option
997
views
1 answers
0 votes
admin asked Mar 30, 2020
997 views
The coupling between different modules of a software is categorized as follows: Content coupling Common couplingControl coupling Stamp CouplingData Coupling Coupling between modules can be ... -VV-IV-III-II-II-III-V-II-IVIV-II-V-III-I
1.0k
views
1 answers
0 votes
admin asked Mar 30, 2020
1,020 views
Which of the following statements are TRUE? The context diagram should depict the system as a single bubble.External entities should be identified clearly at all levels of ... to an external entity.II and IVII and IIII and IIII,II and III
1.1k
views
1 answers
0 votes
admin asked Mar 30, 2020
1,129 views
The Function Points(FP) calculated for software projects are often used to obtain an estimate of Lines of Code(LOC) required for that project. Which of the following ... of a single LOC of FORTRAN.FP and LOC are not related to each other.