
Inheritance is an OOP feature where a new class (derived class) is created from an existing class (base class).
Why we need it:
Example idea:
Employee (name, id)Manager (adds allowance)Derived class can:
Inheritance provides:
Exam line: “Inheritance increases reusability and reduces duplication.”
General syntax:
class Derived : access_mode Base { ... };Example (concept):
class B { ... };class D : public B { ... };Access mode decides how base members are inherited.
One base → one derived
Base → Derived1 → Derived2
Derived inherits from more than one base.
One base → multiple derived classes.
Combination of two or more types.
Access the complete note and unlock all topic-wise content
It's free and takes just 5 seconds
Get instant access to notes, practice questions, and more benefits with our mobile app.
Download this note as PDF at no cost
If any AD appears on download click please wait for 30sec till it gets completed and then close it, you will be redirected to pdf/ppt notes page.
Inheritance is an OOP feature where a new class (derived class) is created from an existing class (base class).
Why we need it:
Example idea:
Employee (name, id)Manager (adds allowance)Derived class can:
Inheritance provides:
Exam line: “Inheritance increases reusability and reduces duplication.”
General syntax:
class Derived : access_mode Base { ... };Example (concept):
class B { ... };class D : public B { ... };Access mode decides how base members are inherited.
One base → one derived
Base → Derived1 → Derived2
Derived inherits from more than one base.
One base → multiple derived classes.
Combination of two or more types.
Access mode controls visibility of inherited members in the derived class.
In Sem 1, focus on the conversion rules table.
Assume base class has members: public, protected, private.
Important: Base private members are not directly accessible in derived class, but they still exist and can be accessed via base’s public/protected member functions.
This is a frequent exam question.
When an object of derived class is created:
When object is destroyed:
Reason (simple): base part must be ready before derived adds its own part.
If base has a parameterized constructor, derived must call it explicitly using initializer list.
Concept:
Derived(int x): Base(x) { ... }This ensures proper initialization.
In multiple inheritance, if both base classes have a member with the same name, calling it from derived may cause ambiguity.
It can be resolved using scope resolution:
Base1::show() or Base2::show()In a diamond structure, a derived class may get two copies of the common base through two paths.
Using virtual base class ensures only one shared base instance.
We keep this as an overview now; detailed treatment comes later.
Single: B → D
Multilevel: B → D1 → D2
Hierarchical: B
↙ ↘
D1 D2
Multiple: B1 B2
↘ ↙
D
Hybrid: (combination)
Create Derived object:
Base constructor → Derived constructor
Destroy Derived object:
Derived destructor → Base destructor
:: helps.From this topic
Inheritance creates a derived class from a base class to reuse code. Advantages (any three):
Thus it is a core OOP feature for large programs.
Single inheritance: one base → one derived (B → D). Multilevel inheritance: base → derived1 → derived2 (B → D1 → D2).
These represent simple inheritance chains.
Inheritance is the process of creating a derived class from a base class so that the derived class can reuse base class members.
Benefits:
Base class (B) → Derived class (D)
D reuses B’s members + adds new features
Thus inheritance reduces duplication and helps build larger programs efficiently.