SlideShare a Scribd company logo
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

PPTX
Introduction to Inheritance
PPTX
Inheritance in OOPS
PPT
Inheritance, Object Oriented Programming
PPTX
Inheritance in c++ by Manan Pasricha
PPTX
Inheritance in c++
PPTX
inheritance in C++
PDF
Inheritance
PPTX
Inheritance
Introduction to Inheritance
Inheritance in OOPS
Inheritance, Object Oriented Programming
Inheritance in c++ by Manan Pasricha
Inheritance in c++
inheritance in C++
Inheritance
Inheritance

What's hot (9)

PPTX
Inheritance
PPTX
Concept of OOPS with real life examples
PPTX
Inheritance
PDF
OOP Inheritance
PPT
PPT
6 Inheritance
PPTX
Inheritance
PPTX
Inheritance
PPTX
Final presentation programming
Inheritance
Concept of OOPS with real life examples
Inheritance
OOP Inheritance
6 Inheritance
Inheritance
Inheritance
Final presentation programming
Ad

Similar to Inheritance (with classifications) (20)

PPS
Inheritance
PPTX
Inheritance
PDF
PDF
OOP Assign No.03(AP).pdf
PPTX
Ritik (inheritance.cpp)
PPSX
Inheritance and Polymorphism in Oops
PPTX
Inheritance.pptx
PPT
Inheritance and its types explained.ppt
PPTX
Inheritance
PPTX
Object Oriented Design and Programming Unit-03
PPT
Inheritance.ppt
PPTX
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
PPT
Lec5.ppt
PPTX
inheritance in C++ programming Language.pptx
PPTX
Inheritance
PPTX
Inheritance in C++
PPTX
inheritance in OOPM
PPTX
INHERITANCES.pptx
PPTX
Inheritance in C++ (Programming Fundamentals)
Inheritance
Inheritance
OOP Assign No.03(AP).pdf
Ritik (inheritance.cpp)
Inheritance and Polymorphism in Oops
Inheritance.pptx
Inheritance and its types explained.ppt
Inheritance
Object Oriented Design and Programming Unit-03
Inheritance.ppt
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
Lec5.ppt
inheritance in C++ programming Language.pptx
Inheritance
Inheritance in C++
inheritance in OOPM
INHERITANCES.pptx
Inheritance in C++ (Programming Fundamentals)
Ad

Recently uploaded (20)

PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
PPT on Performance Review to get promotions
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
Current and future trends in Computer Vision.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
additive manufacturing of ss316l using mig welding
DOCX
573137875-Attendance-Management-System-original
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Safety Seminar civil to be ensured for safe working.
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
OOP with Java - Java Introduction (Basics)
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPT on Performance Review to get promotions
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Current and future trends in Computer Vision.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
CYBER-CRIMES AND SECURITY A guide to understanding
additive manufacturing of ss316l using mig welding
573137875-Attendance-Management-System-original
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
UNIT 4 Total Quality Management .pptx
CH1 Production IntroductoryConcepts.pptx
Digital Logic Computer Design lecture notes
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT

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