SlideShare a Scribd company logo
1 of 32
1, Sajjan Singh Nagar, Opposite Patel Nagar,Raisen Road Bhopal
Computer science and engineering
inheritance
PRESENTED BY
Prof. Firdous Qureshi
0115cs211083
WITH THE GUIDANCE OF
Purushottam singram
INDEX
 INTRODUCTION OF INHERITANCE
 ACCESS CONTROL IN INHERITANCE
 TYPES OF INHERITANCE
 VIRTUAL BASE CLASS & ABSTRACT CLASS
 CONSTRUCTOR IN INHERITANCE
 INHERITANCERITANCE
Inheritance is the mechanism as the capability of class to inherit properties from
another class
BASE CLASSRITANCE
 It is the class whose properties are inherited by
another class it is also called super class
DERIVED CLASS
 It is the class that inherit properties from base
class , it also called sub class
what is inheritance ?
mammal
Dog is a mammal it has all features of
mammals in addition to its own
unique features
cat is a mammal it has all features of
mammals in addition to its own
unique features
All mammals have certain
characteristics
dog cat
Base class
Derived
class
class Base
{
public:
Void call(){
//code
};
};
class derived: public
base
{
public:
Void VideoCall(){
//code
};
};
ACCESS CONTROL IN INHERITANCE
PRIVATE INHERITANCE PROTECTED INHERITANCE PUBLIC INHERITANCE
TANCE
PRIVATE PROTECTED PUBLIC
PRIVATE NOT INHERITED BECOME PRIVATE OF
CHILD CLASS
BECOME PRIVATE OF
CHILD CLASS
PROTECTED NOT INHERITED BECOME PROTECTED
MEMBER OF CHILD CLASS
BECOME PROTECTED OF
CHILD CLASSS
PUBLIC NOT INHERITED BECOME PROTECTED OF
CHILD CLASS
BECOME PUBLIC MEMBER
OF CHILD CLASS
MEMBER OF
BASE CLASS
MEMBER OF
BASE CLASS
MEMBER OF
BASE CLASS
INHERITANCE
TYPE
INHERITANCE
TYPE
INHERITANCE
TYPE
class Base
{
private
int a;
public:
Int b;
};
class Derived: private Base
{
int y;
public:
Int z;
};
In private inheritance protected
and public members of the base
class becomes the private
members of the derived class
 PRIVATE INHERITANCE
class Base
{
private
int a;
public:
Int b;
};
class Derived: protected Base
{
int y;
public:
Int z;
};
In protected inheritance
protected and public members
of the base class becomes the
protected members of the
derived class
 PROTECTED INHERITANCE
class Base
{
private
int a;
public:
Int b;
};
class Derived: public Base
{
int y;
public:
Int z;
}
In public inheritance,
protected members of the base
class becomes the protected
member of derived class
and public members of the base
class becomes the public
members of the derived class
 PUBLIC INHERITANCE
 TYPES OF INHERITANCE
RITANCE
1. Single inheritance
2. Multiple inheritance
3. Multilevel inheritance
4. Hierarchy inheritance
5. Hybrid inheritance
 SINGLE INHERITANCE
Single inheritance is the one here have a single base class and a
derived class
Base class
Derived class
EVOLUTION
INHERITANCE
 SINGLE INHERITANCE
EXAMPLE
class Tire
{
public:
Int pressure = 14;
};
class car : public Tire
{
public:
Int TirePressure( )
{
return pressure;
}
};
main()
{
Car c1;
Cout<<“ pressure in tire is “<<c1.TirePressure()<<endl;
}
#include<iostream>
using namespace std;
Output : -
Pressure in tire is 14
 MULTIPLE INHERITANCE
in multiple inheritance , a derived class inherits from multiple
base classes it has properties of all the base classes
Base class1 base class2 Base class3
Derived class
int main(void)
{
Phone p1;
return 0;
}
class camera
{
public:
camera () {
cout << " I am camera "
<<endl;
}
};
class calculator{
public:
calculator () {
cout << " i am calculator “ <<
endl;
}
};
I am calculator
I am camera
I am phone
Output : -
 MULTIPLE INHERITANCE
EXAMPLE
class phone : public camera,
public calculator
{
public:
phone () {
cout << " i am phone " <<
endl;
}};
#include<iostream>
using namespace std;
 MULTILEVEL INHERITANCE
in multilevel inheritance , a sub class inherits from a class
that it self inherits from another class
Tortilla
Flour
WHEAT
T
CLASS A
CLASS B
CLASS C
BASE CLASS
DERIVED
SECOND
CLASS
DERIVED
FIRST CLASS
 MULTILEVEL INHERITANCE EXAMPLE
class country
{
public:
string countryN = " india ";
};
class state: public country
{
public:
string stateN= " madhaya pradesh
";
};
class district : public state
{
public: string districtN= " bhopal";
district(){
cout<<countryN<<","<<stateN<<","<
<districtN<<endl;
}};
int main()
{
district d1;
return 0;
}
Output : -
india , madhaya pradesh , bhopal
#include<iostream>
using namespace std;
 HIERARCHICAL INHERITANCE
If a number of classes are derived from a single class . It is
called hierarchical inheritance
Civil eng.
computer
eng.
Mech. Eng.
ENGINEER
Derived1 class
Base class
Derived3 class
Derived2 class
 HIERARCHICAL INHERITANCE EXAMPLE
class engineer
{
public:
string eng = "engineer";
};
class computer: public engineer
{
public:
string cs =" computer " +eng;
computer(){
cout<<cs<<endl;
}
};
class civil: public engineer
{
public:
string civ = "civil " + eng;
civil(){ cout<<civ<<endl;
}
};
class mech: public engineer
{
public:
string mec = " mecchanical " +
eng;
mech(){
cout<<mec<<endl;
}
};
int main()
{
civil c1;
computer c2;
mech c3;
}
Output : -
Civil engineer
computer engineer
mechanical engineer
#include<iostream>
using namespace std;
 HYBRID INHERITANCE
it combine two or more types of inheritance . in this type of
inheritance we can have a mixture of different kind of
inheritances
low price
High price
low price
WHOLESALER
RETAILER CONSUMER
MULTILEVEL INHERITANCE
MULTIPLE
INHERITANCE
 HYBRID INHERITANCE EXAMPLE
class wholesaler
{
public:
int price =10;
};
class consumer: virtual public retailer,
virtual public wholesaler
{
public:
consumer(){
cout<<"prices"<<NewPrice<<","<<p
rice<<endl;
}
};
class retailer: virtual public
wholesaler
{
public:
int commission = 2;
int NewPrice = price +
commission;
};
int main()
{
consumer c1;
}
Output : -
prices 12, 10
#include<iostream>
using namespace std;
NCE
 VIRTUAL BASE CLASS IN
INHERITANCE
When classes are derived in the form of
hybrid inheritance there can be a problem by
which multiple copies of the base class
members come in the lowest level derived
class through the various intermediate
subclass , here the virtual base class come
for rescue.
Class base
{
public:
Int a;
};
Class derived1: public base
{
public:
Int b;
};
Class derived2: public base
{
public:
Int c;
};
Class derived3 : public derived1,
public derive2
{
public:
Int d;
};
Class derived1 contains
a and b
Class derived2 contains
a and c
Class derive3 contains
a , b
a, c and d
Here the class derived3
contains three copy data
member a
Because of intermediate
class
Before using virtual base class
Class base
{
public:
Int a;
};
Class derived1: virtual public base
{
public:
Int b;
};
Class derived2: virtual public base
{
public:
Int c;
};
Class derived3 : virtual public
derived1, public derive2
{
public:
Int d;
};
Class derived1 contains
a and b
Class derived2 contains
a and c
Class derived3 only
contains
a , b
c and d
Here the class derived3
contains three copy of
data member a
Because of intermediate
class
After using virtual base class
 ABSTRACT CLASS IN INHERITANCE
it is only designed to be inherited
it provide a framework , upon which other classes
can be built
 It is that has no instance and is not designed to create
objects
int main(void)
{
Derived d;
d.fun();
return 0;
}
class Derived: public Base
{
public:
void fun() { cout << "fun() called"; }
};
class Base
{
int x=10;
public:
virtual void fun() = 0;
int getX() { return x; }
};
Fun() called
Output : -
 ABSTRACT CLASS EXAMPLE
#include<iostream>
using namespace std;
CONSTRUCTOR IN INHERITANCE
If a base class has a parametrized constructor it is
the duty child class to pass the parameters for the
class at the time of creating the object as the
derived class inherit the base class
When an object of a derived class is created the constructor
of the base class is executed first and later the constructor of
derived class
class base {
protected:
int i;
public: base(int x) {
i = x;
cout << "Constructing
base"<<endl;
}
} ;
class derived: public base {
int j;
public:
derived(int x, int y): base(y)
{
j = x;
cout << "Constructing derivedn “ ; }
void show() { cout << i << " " << j << "n"; }
};
#include<iostream>
using namespace std;  Example of constructor in
inheritance
Output : -
int main()
{
derived ob(12, 99);
ob.show();
}
99 12
ADVANTAGE OF INHERITANCE
It saves the memory space and time
It increases the reliability and readability of the code
It saves the developing and testing effort
Thank you !
Purushottam singram
pk9009895@gmail.com
DOWNLOAD PDF WITH
QR CODE

More Related Content

Similar to inheritance in OOPM

Similar to inheritance in OOPM (20)

Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
10 inheritance
10 inheritance10 inheritance
10 inheritance
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Object Oriented Programming - Inheritance
Object Oriented Programming - InheritanceObject Oriented Programming - Inheritance
Object Oriented Programming - Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptxINHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
 
Inheritance
InheritanceInheritance
Inheritance
 
inheritance in C++
inheritance in C++inheritance in C++
inheritance in C++
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture4
Lecture4Lecture4
Lecture4
 
Unit3 java
Unit3 javaUnit3 java
Unit3 java
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Lecture4
Lecture4Lecture4
Lecture4
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
 

Recently uploaded

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 

Recently uploaded (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

inheritance in OOPM

  • 1. 1, Sajjan Singh Nagar, Opposite Patel Nagar,Raisen Road Bhopal Computer science and engineering
  • 2. inheritance PRESENTED BY Prof. Firdous Qureshi 0115cs211083 WITH THE GUIDANCE OF Purushottam singram
  • 3. INDEX  INTRODUCTION OF INHERITANCE  ACCESS CONTROL IN INHERITANCE  TYPES OF INHERITANCE  VIRTUAL BASE CLASS & ABSTRACT CLASS  CONSTRUCTOR IN INHERITANCE
  • 4.  INHERITANCERITANCE Inheritance is the mechanism as the capability of class to inherit properties from another class BASE CLASSRITANCE  It is the class whose properties are inherited by another class it is also called super class DERIVED CLASS  It is the class that inherit properties from base class , it also called sub class
  • 5. what is inheritance ? mammal Dog is a mammal it has all features of mammals in addition to its own unique features cat is a mammal it has all features of mammals in addition to its own unique features All mammals have certain characteristics dog cat
  • 6. Base class Derived class class Base { public: Void call(){ //code }; }; class derived: public base { public: Void VideoCall(){ //code }; };
  • 7. ACCESS CONTROL IN INHERITANCE PRIVATE INHERITANCE PROTECTED INHERITANCE PUBLIC INHERITANCE
  • 8. TANCE PRIVATE PROTECTED PUBLIC PRIVATE NOT INHERITED BECOME PRIVATE OF CHILD CLASS BECOME PRIVATE OF CHILD CLASS PROTECTED NOT INHERITED BECOME PROTECTED MEMBER OF CHILD CLASS BECOME PROTECTED OF CHILD CLASSS PUBLIC NOT INHERITED BECOME PROTECTED OF CHILD CLASS BECOME PUBLIC MEMBER OF CHILD CLASS MEMBER OF BASE CLASS MEMBER OF BASE CLASS MEMBER OF BASE CLASS INHERITANCE TYPE INHERITANCE TYPE INHERITANCE TYPE
  • 9. class Base { private int a; public: Int b; }; class Derived: private Base { int y; public: Int z; }; In private inheritance protected and public members of the base class becomes the private members of the derived class  PRIVATE INHERITANCE
  • 10. class Base { private int a; public: Int b; }; class Derived: protected Base { int y; public: Int z; }; In protected inheritance protected and public members of the base class becomes the protected members of the derived class  PROTECTED INHERITANCE
  • 11. class Base { private int a; public: Int b; }; class Derived: public Base { int y; public: Int z; } In public inheritance, protected members of the base class becomes the protected member of derived class and public members of the base class becomes the public members of the derived class  PUBLIC INHERITANCE
  • 12.  TYPES OF INHERITANCE RITANCE 1. Single inheritance 2. Multiple inheritance 3. Multilevel inheritance 4. Hierarchy inheritance 5. Hybrid inheritance
  • 13.  SINGLE INHERITANCE Single inheritance is the one here have a single base class and a derived class Base class Derived class EVOLUTION INHERITANCE
  • 14.  SINGLE INHERITANCE EXAMPLE class Tire { public: Int pressure = 14; }; class car : public Tire { public: Int TirePressure( ) { return pressure; } }; main() { Car c1; Cout<<“ pressure in tire is “<<c1.TirePressure()<<endl; } #include<iostream> using namespace std; Output : - Pressure in tire is 14
  • 15.  MULTIPLE INHERITANCE in multiple inheritance , a derived class inherits from multiple base classes it has properties of all the base classes Base class1 base class2 Base class3 Derived class
  • 16. int main(void) { Phone p1; return 0; } class camera { public: camera () { cout << " I am camera " <<endl; } }; class calculator{ public: calculator () { cout << " i am calculator “ << endl; } }; I am calculator I am camera I am phone Output : -  MULTIPLE INHERITANCE EXAMPLE class phone : public camera, public calculator { public: phone () { cout << " i am phone " << endl; }}; #include<iostream> using namespace std;
  • 17.  MULTILEVEL INHERITANCE in multilevel inheritance , a sub class inherits from a class that it self inherits from another class Tortilla Flour WHEAT T CLASS A CLASS B CLASS C BASE CLASS DERIVED SECOND CLASS DERIVED FIRST CLASS
  • 18.  MULTILEVEL INHERITANCE EXAMPLE class country { public: string countryN = " india "; }; class state: public country { public: string stateN= " madhaya pradesh "; }; class district : public state { public: string districtN= " bhopal"; district(){ cout<<countryN<<","<<stateN<<","< <districtN<<endl; }}; int main() { district d1; return 0; } Output : - india , madhaya pradesh , bhopal #include<iostream> using namespace std;
  • 19.  HIERARCHICAL INHERITANCE If a number of classes are derived from a single class . It is called hierarchical inheritance Civil eng. computer eng. Mech. Eng. ENGINEER Derived1 class Base class Derived3 class Derived2 class
  • 20.  HIERARCHICAL INHERITANCE EXAMPLE class engineer { public: string eng = "engineer"; }; class computer: public engineer { public: string cs =" computer " +eng; computer(){ cout<<cs<<endl; } }; class civil: public engineer { public: string civ = "civil " + eng; civil(){ cout<<civ<<endl; } }; class mech: public engineer { public: string mec = " mecchanical " + eng; mech(){ cout<<mec<<endl; } }; int main() { civil c1; computer c2; mech c3; } Output : - Civil engineer computer engineer mechanical engineer #include<iostream> using namespace std;
  • 21.  HYBRID INHERITANCE it combine two or more types of inheritance . in this type of inheritance we can have a mixture of different kind of inheritances low price High price low price WHOLESALER RETAILER CONSUMER MULTILEVEL INHERITANCE MULTIPLE INHERITANCE
  • 22.  HYBRID INHERITANCE EXAMPLE class wholesaler { public: int price =10; }; class consumer: virtual public retailer, virtual public wholesaler { public: consumer(){ cout<<"prices"<<NewPrice<<","<<p rice<<endl; } }; class retailer: virtual public wholesaler { public: int commission = 2; int NewPrice = price + commission; }; int main() { consumer c1; } Output : - prices 12, 10 #include<iostream> using namespace std;
  • 23. NCE  VIRTUAL BASE CLASS IN INHERITANCE When classes are derived in the form of hybrid inheritance there can be a problem by which multiple copies of the base class members come in the lowest level derived class through the various intermediate subclass , here the virtual base class come for rescue.
  • 24. Class base { public: Int a; }; Class derived1: public base { public: Int b; }; Class derived2: public base { public: Int c; }; Class derived3 : public derived1, public derive2 { public: Int d; }; Class derived1 contains a and b Class derived2 contains a and c Class derive3 contains a , b a, c and d Here the class derived3 contains three copy data member a Because of intermediate class Before using virtual base class
  • 25. Class base { public: Int a; }; Class derived1: virtual public base { public: Int b; }; Class derived2: virtual public base { public: Int c; }; Class derived3 : virtual public derived1, public derive2 { public: Int d; }; Class derived1 contains a and b Class derived2 contains a and c Class derived3 only contains a , b c and d Here the class derived3 contains three copy of data member a Because of intermediate class After using virtual base class
  • 26.  ABSTRACT CLASS IN INHERITANCE it is only designed to be inherited it provide a framework , upon which other classes can be built  It is that has no instance and is not designed to create objects
  • 27. int main(void) { Derived d; d.fun(); return 0; } class Derived: public Base { public: void fun() { cout << "fun() called"; } }; class Base { int x=10; public: virtual void fun() = 0; int getX() { return x; } }; Fun() called Output : -  ABSTRACT CLASS EXAMPLE #include<iostream> using namespace std;
  • 28. CONSTRUCTOR IN INHERITANCE If a base class has a parametrized constructor it is the duty child class to pass the parameters for the class at the time of creating the object as the derived class inherit the base class When an object of a derived class is created the constructor of the base class is executed first and later the constructor of derived class
  • 29. class base { protected: int i; public: base(int x) { i = x; cout << "Constructing base"<<endl; } } ; class derived: public base { int j; public: derived(int x, int y): base(y) { j = x; cout << "Constructing derivedn “ ; } void show() { cout << i << " " << j << "n"; } }; #include<iostream> using namespace std;  Example of constructor in inheritance Output : - int main() { derived ob(12, 99); ob.show(); } 99 12
  • 30. ADVANTAGE OF INHERITANCE It saves the memory space and time It increases the reliability and readability of the code It saves the developing and testing effort
  • 31. Thank you ! Purushottam singram pk9009895@gmail.com