Saturday 31 October 2015

QUIZ(click here to view)

       QUIZ on OOPS(will keep posting various quiz questions)





C++ | Inheritance | Question 1


#include<iostream>
  
using namespace std;
class Base1 {
 public:
     Base1()
     { cout << " Base1's constructor called" << endl;  }
};
  
class Base2 {
 public:
     Base2()
     { cout << "Base2's constructor called" << endl;  }
};
  
class Derived: public Base1, public Base2 {
   public:
     Derived()
     {  cout << "Derived's constructor called" << endl;  }
};
  
int main()
{
   Derived d;
   return 0;
}


OPTIONS:



(A) Compiler Dependent


(B) Base1′s constructor called
Base2′s constructor called
Derived’s constructor called


(C) Base2′s constructor called
Base1′s constructor called
Derived’s constructor called


(D) Compiler Error



-SPECIAL PROBLEMS ON INHERITANCE(click here to view)

THIS POST IS BASICALLY EXPLAINING THE SPECIAL PROBLEMS IN INHERITANCE..will keep updating 



The diamond problem

The diamond problem occurs when two superclasses of a class have a common base class. For example, in the following diagram, the TA class gets two copies of all attributes of Person class, this causes ambiguities.