Inheritance Interview Questions

    Question 1C++ OOPS - Basic Inheritance Concept

    Which keyword is used in C++ to inherit a class?

    Question 2C++ OOPS - Types of Inheritance

    Which of the following is NOT a type of inheritance in C++?

    Question 3C++ OOPS - Access Specifier in Inheritance

    If a base class is inherited as private, what happens to its public members in the derived class?

    Question 4C++ OOPS - Code Example Single Inheritance

    What will be the output of the following code?

    #include<iostream> using namespace std; class A { public: void show() { cout << "Class A"; } }; class B : public A {}; int main() { B obj; obj.show(); }

    Question 5C++ OOPS - Multilevel Inheritance Code

    What will the following program print?

    #include<iostream> using namespace std; class A { public: void display() { cout << "A "; } }; class B : public A { public: void displayB() { cout << "B "; } }; class C : public B { public: void displayC() { cout << "C"; } }; int main() { C obj; obj.display(); obj.displayB(); obj.displayC(); }

    Question 6C++ OOPS - Diamond Problem

    The "diamond problem" occurs in which type of inheritance?

    Question 7C++ OOPS - Virtual Inheritance

    Which keyword is used to solve the diamond problem in C++?

    Question 8C++ OOPS - Constructor Call Order

    In inheritance, what is the order of constructor calls?

    Question 9C++ OOPS - Protected Members in Inheritance

    If a member is declared protected in the base class, how is it inherited in a public derived class?

    Question 10C++ OOPS - Function Overriding Code

    What will the following code output?

    #include<iostream> using namespace std; class Base { public: void show() { cout << "Base"; } }; class Derived : public Base { public: void show() { cout << "Derived"; } }; int main() { Derived d; d.show(); }