SlideShare a Scribd company logo
1 of 23
Inheritance (with
Classifications)
Created by: Redwan islam
E-mail:redwanislamdip@gmail.com
Introduction of inheritance:
 One of the most important concepts in object-oriented
programming is that of inheritance. Inheritance allows us to
define a class in terms of another class, which makes it easier to
create and maintain an application. This also provides an
opportunity to reuse the code functionality and fast
implementation time.
 When creating a class, instead of writing completely new data
members and member functions, the programmer can designate
that the new class should inherit the members of an existing
class. This existing class is called the base class, and the new
class is referred to as the derived class.
Definition
 The Capability of a class to derive properties and characteristics
from another class is called inheritance.
 The derived class inherits all the features from the base class
and can have additional features of its own.
 Inheritance is one of the most important feature of Object
Oriented Programming.
Sample Example
#include <iostream>
using namespace std;
// Base class
class Shape {
public:
void setWidth(int w) {
width = w;
}
void setHeight(int h) {
height = h;
}
protected:
int width;
int height;
};
// Derived class
class Rectangle: public Shape {
public:
int getArea() {
return (width * height);
}
};
int main(void) {
Rectangle Rect;
Rect.setWidth(5);
Rect.setHeight(7);
// Print the area of the object.
cout << "Total area: " << Rect.getArea() << endl;
return 0;
}
Classifications:
In C++, We have 5 different types of Inheritance. Namely
 Single Inheritance
 Multilevel Inheritance
 Multiple Inheritance
 Hierarchical Inheritance
 Hybrid Inheritance (also known as Virtual Inheritance)
Classifications:
In C++, We have another types of Inheritance. Namely
 Multipath Inheritance(It’s a part of inheritance,and it’s use as
ambiguity)
Single inheritance
In this inheritance, a derived class is created from
a single base class.
Class A
Class B
Sample Program
//Base Class
Class A {
public void fooA() {
//TO DO:
}
}
//Derived Class
Class B : A {
public void fooB() {
//TO DO:
}
}
Multi-level inheritance
In this inheritance, a derived class is created from
another derived class.
Class A
Class B
Class C
Sample Program
//Base Class
class A {
public void fooA() {
//TO DO:
}
}
//Derived Class
class B : A {
public void fooB() {
//TO DO:
}
}
//Derived Class
class C : B {
public void fooC() {
//TO DO:
}
}
Multiple inheritance
In this inheritance, a derived class is created from
more than one base class. This inheritance is not
supported by .NET Languages like C#, F# etc.
Class A Class B
Class C
Sample Program
//Base Class
class A {
public void fooA() {
//TO DO:
}
}
//Derived Class
class B {
public void fooB() {
//TO DO:
}
}
//Derived Class
class C : A, B {
public void fooC() {
//TO DO:
}
}
Hierarchical inheritance
In this inheritance, more than one derived classes are
created from a single base.
Class C Class B
Class D
Class A
Class E Class F Class G
Sample Program
//Base Class
class A {
public void fooA() {
//TO DO:
}
}
//Derived Class
class B : A {
public void fooB() {
//TO DO:
}
}
//Derived Class
class C : A {
public void fooC() {
//TO DO:
}
}
//Derived Class
class D : C {
public void fooD() {
//TO DO:
}
}
Sample Program
//Base Class
class E:C {
public void fooE() {
//TO DO:
}
}
//Derived Class
class F : B {
public void fooF() {
//TO DO:
}
}
//Derived Class
class G: B {
public void fooG() {
//TO DO:
}
}
Hybrid inheritance
This is combination of more than one inheritance. Hence, it
may be a combination of Multilevel and Multiple inheritance
or Hierarchical and Multilevel inheritance or Hierarchical
and Multipath inheritance or Hierarchical, Multilevel and
Multiple inheritance.
Hybrid inheritance
Class FClass A
Class C Class B
Class EClass D
Sample Program
//Base Class
class A {
public void fooA() {
//TO DO:
}
}
//Derived Class
class F {
public void fooF() {
//TO DO:
}
}
//Derived Class
class B: A, F{
public void fooB() {
//TO DO:
}
}
//Derived Class
class C : A{
public void fooC() {
//TO DO:
}
}
Sample Program
//Base Class
class D: C {
public void fooD() {
//TO DO:
}
}
//Derived Class
class E : C{
public void fooE() {
//TO DO:
}
}
Multipath inheritance
In this inheritance, a derived class is created from another
derived classes and the same base class of another derived
classes. This inheritance is not supported by .NET Languages
like C#, F# etc.
Class D Class B
Class C
Class A
Multipath inheritance
//Base Class
class A {
public void fooA() {
//TO DO:
}
}
//Derived Class
class B : A {
public void fooB() {
//TO DO:
}
}
//Derived Class
class C : A {
public void fooC() {
//TO DO:
}
}
//Derived Class
class D : B, A, C {
public void fooD() {
//TO DO:
}
}
If you need any kind of information
just contact me.
E-mail: redwanislamdip@gmail.com
Thank you !!!

More Related Content

What's hot (9)

Inheritance
Inheritance Inheritance
Inheritance
 
Concept of OOPS with real life examples
Concept of OOPS with real life examplesConcept of OOPS with real life examples
Concept of OOPS with real life examples
 
Inheritance
InheritanceInheritance
Inheritance
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
 
OOP
OOPOOP
OOP
 
6 Inheritance
6 Inheritance6 Inheritance
6 Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Final presentation programming
Final presentation programmingFinal presentation programming
Final presentation programming
 

Similar to Inheritance (with classifications)

Similar to Inheritance (with classifications) (20)

Inheritance
InheritanceInheritance
Inheritance
 
Programming Lesson by Slidesgo.pptx
Programming Lesson by Slidesgo.pptxProgramming Lesson by Slidesgo.pptx
Programming Lesson by Slidesgo.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Ritik (inheritance.cpp)
Ritik (inheritance.cpp)Ritik (inheritance.cpp)
Ritik (inheritance.cpp)
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
OOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdfOOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdf
 
iheritence.pptx
iheritence.pptxiheritence.pptx
iheritence.pptx
 
Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 
Inheritance.ppt
Inheritance.pptInheritance.ppt
Inheritance.ppt
 
Inheritance in c++theory
Inheritance in c++theoryInheritance in c++theory
Inheritance in c++theory
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Inheritance
InheritanceInheritance
Inheritance
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 

Inheritance (with classifications)

  • 1. Inheritance (with Classifications) Created by: Redwan islam E-mail:redwanislamdip@gmail.com
  • 2. Introduction of inheritance:  One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.  When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.
  • 3. Definition  The Capability of a class to derive properties and characteristics from another class is called inheritance.  The derived class inherits all the features from the base class and can have additional features of its own.  Inheritance is one of the most important feature of Object Oriented Programming.
  • 4. Sample Example #include <iostream> using namespace std; // Base class class Shape { public: void setWidth(int w) { width = w; } void setHeight(int h) { height = h; } protected: int width; int height; }; // Derived class class Rectangle: public Shape { public: int getArea() { return (width * height); } }; int main(void) { Rectangle Rect; Rect.setWidth(5); Rect.setHeight(7); // Print the area of the object. cout << "Total area: " << Rect.getArea() << endl; return 0; }
  • 5. Classifications: In C++, We have 5 different types of Inheritance. Namely  Single Inheritance  Multilevel Inheritance  Multiple Inheritance  Hierarchical Inheritance  Hybrid Inheritance (also known as Virtual Inheritance)
  • 6. Classifications: In C++, We have another types of Inheritance. Namely  Multipath Inheritance(It’s a part of inheritance,and it’s use as ambiguity)
  • 7. Single inheritance In this inheritance, a derived class is created from a single base class. Class A Class B
  • 8. Sample Program //Base Class Class A { public void fooA() { //TO DO: } } //Derived Class Class B : A { public void fooB() { //TO DO: } }
  • 9. Multi-level inheritance In this inheritance, a derived class is created from another derived class. Class A Class B Class C
  • 10. Sample Program //Base Class class A { public void fooA() { //TO DO: } } //Derived Class class B : A { public void fooB() { //TO DO: } } //Derived Class class C : B { public void fooC() { //TO DO: } }
  • 11. Multiple inheritance In this inheritance, a derived class is created from more than one base class. This inheritance is not supported by .NET Languages like C#, F# etc. Class A Class B Class C
  • 12. Sample Program //Base Class class A { public void fooA() { //TO DO: } } //Derived Class class B { public void fooB() { //TO DO: } } //Derived Class class C : A, B { public void fooC() { //TO DO: } }
  • 13. Hierarchical inheritance In this inheritance, more than one derived classes are created from a single base. Class C Class B Class D Class A Class E Class F Class G
  • 14. Sample Program //Base Class class A { public void fooA() { //TO DO: } } //Derived Class class B : A { public void fooB() { //TO DO: } } //Derived Class class C : A { public void fooC() { //TO DO: } } //Derived Class class D : C { public void fooD() { //TO DO: } }
  • 15. Sample Program //Base Class class E:C { public void fooE() { //TO DO: } } //Derived Class class F : B { public void fooF() { //TO DO: } } //Derived Class class G: B { public void fooG() { //TO DO: } }
  • 16. Hybrid inheritance This is combination of more than one inheritance. Hence, it may be a combination of Multilevel and Multiple inheritance or Hierarchical and Multilevel inheritance or Hierarchical and Multipath inheritance or Hierarchical, Multilevel and Multiple inheritance.
  • 17. Hybrid inheritance Class FClass A Class C Class B Class EClass D
  • 18. Sample Program //Base Class class A { public void fooA() { //TO DO: } } //Derived Class class F { public void fooF() { //TO DO: } } //Derived Class class B: A, F{ public void fooB() { //TO DO: } } //Derived Class class C : A{ public void fooC() { //TO DO: } }
  • 19. Sample Program //Base Class class D: C { public void fooD() { //TO DO: } } //Derived Class class E : C{ public void fooE() { //TO DO: } }
  • 20. Multipath inheritance In this inheritance, a derived class is created from another derived classes and the same base class of another derived classes. This inheritance is not supported by .NET Languages like C#, F# etc. Class D Class B Class C Class A
  • 21. Multipath inheritance //Base Class class A { public void fooA() { //TO DO: } } //Derived Class class B : A { public void fooB() { //TO DO: } } //Derived Class class C : A { public void fooC() { //TO DO: } } //Derived Class class D : B, A, C { public void fooD() { //TO DO: } }
  • 22. If you need any kind of information just contact me. E-mail: redwanislamdip@gmail.com