0% found this document useful (0 votes)
5 views4 pages

Inheritance Concepts

Uploaded by

AnanyaKannan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Inheritance Concepts

Uploaded by

AnanyaKannan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

🔹 1.

Basic Inheritance
 Deriving one class from another using:
o public

o protected

o private inheritance

🔹 2. Types of Inheritance
 Single Inheritance
 Multiple Inheritance
 Multilevel Inheritance
 Hierarchical Inheritance
 Hybrid Inheritance

🔹 3. Access Specifiers in Inheritance


 Effects of public, protected, private inheritance on base class members.

🔹 4. Base and Derived Class Constructors


 Constructor and destructor calling order.
 Initialization list for base class.

🔹 5. Function Overriding
 Redefining base class method in derived class.
 Use of virtual keyword.

🔹 6. virtual Functions & Polymorphism


 Runtime Polymorphism
 Use of virtual, override, and final
 Virtual Tables (vtable)

🔹 7. Abstract Classes
 Class with at least one pure virtual function:
 virtual void display() = 0;
🔹 8. super Equivalent: BaseClass:: Syntax
 Access base class functions/members using scope resolution:
 Base::function();

🔹 9. Object Slicing
 Losing derived part when assigning to a base class object.

🔹 10. protected Access Modifier


 Accessible in derived class but not outside.

🔹 11. Diamond Problem


 Occurs in multiple inheritance when two base classes have a common
base.
 Solved using virtual inheritance:
 class A {};
 class B : virtual public A {};
 class C : virtual public A {};
 class D : public B, public C {};

🔹 12. Virtual Base Classes


 Used to prevent duplication in diamond inheritance.
pros and cons of all types of inheritance in object-oriented programming
(OOP) C++

1. Single Inheritance
Definition: A class inherits from only one base class.
Pros Cons

Simpler and easy to Limited reuse if functionality is spread across


understand multiple classes

Less ambiguity and cleaner Can't model relationships requiring multiple base
design classes

2. Multiple Inheritance
Definition: A class inherits from more than one base class.
Pros Cons

Allows combining functionalities from Increases complexity


multiple sources

Better code reuse Risk of ambiguity (e.g., diamond


problem)

Models multiple relationships well Complicated constructor and


destructor calls

3. Multilevel Inheritance
Definition: A class is derived from a class which is already derived from another
class (chain-like).
Pros Cons

Promotes reusability across a Can become hard to trace inherited


hierarchy features

Easier to model hierarchical Changes in base classes can have ripple


relationships effects

4. Hierarchical Inheritance
Definition: Multiple classes inherit from a single base class.
Pros Cons

Reuse of common functionality in Changes in the base class affect all


multiple derived classes derived classes
Reduces code duplication Poor design may lead to fragile
base class problem

5. Hybrid Inheritance
Definition: Combination of more than one type of inheritance (e.g., multiple +
multilevel).
Pros Cons

Highly flexible and Very complex structure


powerful

Supports real-world Needs virtual inheritance to avoid


modeling diamond problem

Maximizes code reuse Debugging and maintenance become


difficult

You might also like