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

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
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
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
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
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 

Recently uploaded (20)

POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort 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
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
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
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
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
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
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
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 

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