SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Presentation topic
Inheritance
Multilevel Inheritance
Multiple Inheritance
Hierarchical Inheritance
Group Members:
Mehak Ashfaq(001)
Sahar Ashfaq(002)
Tayyaba Nawaz(003)
What is Inheritance???
 It is very powerful feature in OOP.
 It is a concept in which the properties
of one class are available for other
class.
 The class that is being inherited is
called super class.
 The class that inherits the properties
and functions of super class is called
sub class.
Types of Inheritance:
 Multilevel inheritance
 Multiple inheritance
 Hierarchical inheritance
Multilevel Inheritance
 In this one class is inherit from base
class.
 Then this derived class becomes base
class of another class.
 Thus the class in center is called
Intermediate class.
Diagram or flow
Syntax :
 Class Person
 {……};
 Class Doctor:public Person
 {……..};
 Class Surgeon:public Doctor
 {……};
Example program
#include<iostream>
using namespace std;
class person
{
protected:
string name;
int phone_No;
public:
void setdata(string n,int p)
{
name=n;
phone_No=p;
}
void showData()
{
cout<<"name="<<name<<endl;
cout<<"phone-
no="<<phone_No<<endl;
}
};
class doctor:public person
{
protected:
int Id;
public:
void treat()
{
cout<<"dostors treat patients"<<endl;
}
};
class surgeon:public doctor
{
public:
void operate()
{
cout<<"surgeon operates....."<<endl;
}
};
 int main()
 {
 surgeon s;
 s.setdata(“mehak",123);
 s.showData();
 s.operate();
 s.treat();
 system("pause");
 }
Multiple Inheritance:
 In this type of inheritance there are
more than one base classes.
 And one class is inherit from these
base classes.
 The derived class has all the public
and protected properties of all base
classes.
 These base classes are separated by
commas in syntax.
Flow or diagram
Syntax:
 Class A
 {….};
 Class B
 {…};
 Class C :public A , Public B
 {….};
Example program
 #include<iostream>
 using namespace std;
 class father
 {
 private:
 string name;
 int phone_No;
 public:
 void function()
 {
 cout<<"father function....."<<endl;
 }
 };
 class mother
 public:
 void cook()
 {
 cout<<"mother cook food...."<<endl;
 }
 };
 class son
 public:
 void learn()
 {
 cout<<"son learn from books....."<<endl;
 }
 };
 int main()
 {
 son s1;
 s1.function();
 s1.cook();
 s1.learn();
 system("pause");
 }
Hierarchical Inheritance:
 In this every class has only one base
class.
 But a base class has many sub
classes.
 This form may b represent like a tree.
 Each derived class serves as a base
class of lower classes.
Flow or diagram
Example program
 #include<iostream>
 using namespace std;
 class person
 {
 protected:
 string name;
 int phone;
 public:
 void setData(string n, int p)
 {
 name=n;
 phone=p;

 }
 void showData()
 {
 cout<<"name and phone no are
"<<name<<endl<<phone<<endl;
 }
 };
 class doctor:public person
 {
 public:
 void treats()
 {
 cout<<"doctor treats patients...."<<endl;
 }
 };
 class dentist:public doctor
 {
 public:

 void clean()
 {
 cout<<"dentist cleans patient's
teeth"<<endl;
 }

 };
 class teacher: public person
 {
 public:
 void teach()
 {
 cout<<"teacher teach students...."<<endl;
 }
 };
 class head:public teacher
 {
 public:
 void control()
 {
 cout<<"head control overall working of
institute...."<<endl;
 }
 };
 int main()
 {
 dentist d1;
 d1.setData("tayyaba",2345);
 d1.showData();
 d1.treats();
 d1.clean();
 head h1;
 h1.setData("tayyaba",8976);
 h1.showData();
 h1.teach();
 h1.control();

 system("pause");
 }

Weitere ähnliche Inhalte

Was ist angesagt?

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oopsHirra Sultan
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packagesVINOTH R
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in javaHrithikShinde
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vishal Patil
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Paumil Patel
 
Access specifiers (Public Private Protected) C++
Access specifiers (Public Private  Protected) C++Access specifiers (Public Private  Protected) C++
Access specifiers (Public Private Protected) C++vivekkumar2938
 
Inheritance
InheritanceInheritance
InheritanceTech_MX
 
Access specifier
Access specifierAccess specifier
Access specifierzindadili
 
Exception Handling
Exception HandlingException Handling
Exception HandlingReddhi Basu
 

Was ist angesagt? (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Method overriding
Method overridingMethod overriding
Method overriding
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Exception handling
Exception handlingException handling
Exception handling
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in java
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Operators in java
Operators in javaOperators in java
Operators in java
 
inheritance
inheritanceinheritance
inheritance
 
Access specifiers (Public Private Protected) C++
Access specifiers (Public Private  Protected) C++Access specifiers (Public Private  Protected) C++
Access specifiers (Public Private Protected) C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Access specifier
Access specifierAccess specifier
Access specifier
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 

Andere mochten auch

C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritanceharshaltambe
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritanceadil raja
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple InheritanceMichal Píše
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...cprogrammings
 
Admission in india 2015
Admission in india 2015Admission in india 2015
Admission in india 2015Edhole.com
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritanceShrija Madhu
 
Linear Systems Gauss Seidel
Linear Systems   Gauss SeidelLinear Systems   Gauss Seidel
Linear Systems Gauss SeidelEric Davishahl
 
Matemáticas II ecuaciones lineales
Matemáticas II   ecuaciones linealesMatemáticas II   ecuaciones lineales
Matemáticas II ecuaciones linealesanalaura_fdz
 
Solución de sistemas de ecuaciones lineales.
Solución de sistemas de ecuaciones lineales. Solución de sistemas de ecuaciones lineales.
Solución de sistemas de ecuaciones lineales. Alida Marleny Ros Medrano
 
Jacobi and gauss-seidel
Jacobi and gauss-seidelJacobi and gauss-seidel
Jacobi and gauss-seidelarunsmm
 
Load flow study
Load flow studyLoad flow study
Load flow studyf s
 

Andere mochten auch (20)

C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
 
Inheritance
InheritanceInheritance
Inheritance
 
Oop
OopOop
Oop
 
Andrealozada
AndrealozadaAndrealozada
Andrealozada
 
Admission in india 2015
Admission in india 2015Admission in india 2015
Admission in india 2015
 
Inheritance
InheritanceInheritance
Inheritance
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Es272 ch4b
Es272 ch4bEs272 ch4b
Es272 ch4b
 
inheritance
inheritanceinheritance
inheritance
 
Linear Systems Gauss Seidel
Linear Systems   Gauss SeidelLinear Systems   Gauss Seidel
Linear Systems Gauss Seidel
 
Gauss seidel
Gauss seidelGauss seidel
Gauss seidel
 
Matemáticas II ecuaciones lineales
Matemáticas II   ecuaciones linealesMatemáticas II   ecuaciones lineales
Matemáticas II ecuaciones lineales
 
Solución de sistemas de ecuaciones lineales.
Solución de sistemas de ecuaciones lineales. Solución de sistemas de ecuaciones lineales.
Solución de sistemas de ecuaciones lineales.
 
Jacobi and gauss-seidel
Jacobi and gauss-seidelJacobi and gauss-seidel
Jacobi and gauss-seidel
 
Load flow study
Load flow studyLoad flow study
Load flow study
 

Ähnlich wie inheritance in C++

INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptxINHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptxDeepasCSE
 
inheritance in OOPM
inheritance in OOPMinheritance in OOPM
inheritance in OOPMPKKArc
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdfstudy material
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.pptEmanAsem4
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
Constructor&method
Constructor&methodConstructor&method
Constructor&methodJani Harsh
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interfaceShubham Sharma
 
oop database doc for studevsgdy fdsyn hdf
oop database doc for studevsgdy fdsyn hdfoop database doc for studevsgdy fdsyn hdf
oop database doc for studevsgdy fdsyn hdfitxminahil29
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPAlena Holligan
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental PrinciplesIntro C# Book
 

Ähnlich wie inheritance in C++ (20)

INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptxINHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Inheritance
InheritanceInheritance
Inheritance
 
inheritance in OOPM
inheritance in OOPMinheritance in OOPM
inheritance in OOPM
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Constructor&method
Constructor&methodConstructor&method
Constructor&method
 
Oopc (group 9)
Oopc (group 9)Oopc (group 9)
Oopc (group 9)
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
 
oop database doc for studevsgdy fdsyn hdf
oop database doc for studevsgdy fdsyn hdfoop database doc for studevsgdy fdsyn hdf
oop database doc for studevsgdy fdsyn hdf
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHP
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 

Kürzlich hochgeladen

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 

Kürzlich hochgeladen (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 

inheritance in C++

  • 2. Group Members: Mehak Ashfaq(001) Sahar Ashfaq(002) Tayyaba Nawaz(003)
  • 3. What is Inheritance???  It is very powerful feature in OOP.  It is a concept in which the properties of one class are available for other class.  The class that is being inherited is called super class.  The class that inherits the properties and functions of super class is called sub class.
  • 4. Types of Inheritance:  Multilevel inheritance  Multiple inheritance  Hierarchical inheritance
  • 5. Multilevel Inheritance  In this one class is inherit from base class.  Then this derived class becomes base class of another class.  Thus the class in center is called Intermediate class.
  • 7. Syntax :  Class Person  {……};  Class Doctor:public Person  {……..};  Class Surgeon:public Doctor  {……};
  • 8. Example program #include<iostream> using namespace std; class person { protected: string name; int phone_No; public: void setdata(string n,int p) { name=n; phone_No=p; }
  • 10. class doctor:public person { protected: int Id; public: void treat() { cout<<"dostors treat patients"<<endl; } }; class surgeon:public doctor { public: void operate() { cout<<"surgeon operates....."<<endl; } };
  • 11.  int main()  {  surgeon s;  s.setdata(“mehak",123);  s.showData();  s.operate();  s.treat();  system("pause");  }
  • 12. Multiple Inheritance:  In this type of inheritance there are more than one base classes.  And one class is inherit from these base classes.  The derived class has all the public and protected properties of all base classes.  These base classes are separated by commas in syntax.
  • 14. Syntax:  Class A  {….};  Class B  {…};  Class C :public A , Public B  {….};
  • 15. Example program  #include<iostream>  using namespace std;  class father  {  private:  string name;  int phone_No;  public:  void function()  {  cout<<"father function....."<<endl;  }  };  class mother  public:  void cook()  {  cout<<"mother cook food...."<<endl;  }  };
  • 16.  class son  public:  void learn()  {  cout<<"son learn from books....."<<endl;  }  };  int main()  {  son s1;  s1.function();  s1.cook();  s1.learn();  system("pause");  }
  • 17. Hierarchical Inheritance:  In this every class has only one base class.  But a base class has many sub classes.  This form may b represent like a tree.  Each derived class serves as a base class of lower classes.
  • 19. Example program  #include<iostream>  using namespace std;  class person  {  protected:  string name;  int phone;  public:  void setData(string n, int p)  {  name=n;  phone=p;   }  void showData()  {  cout<<"name and phone no are "<<name<<endl<<phone<<endl;  }  };
  • 20.  class doctor:public person  {  public:  void treats()  {  cout<<"doctor treats patients...."<<endl;  }  };  class dentist:public doctor  {  public:   void clean()  {  cout<<"dentist cleans patient's teeth"<<endl;  }   };
  • 21.  class teacher: public person  {  public:  void teach()  {  cout<<"teacher teach students...."<<endl;  }  };  class head:public teacher  {  public:  void control()  {  cout<<"head control overall working of institute...."<<endl;  }  };
  • 22.  int main()  {  dentist d1;  d1.setData("tayyaba",2345);  d1.showData();  d1.treats();  d1.clean();  head h1;  h1.setData("tayyaba",8976);  h1.showData();  h1.teach();  h1.control();   system("pause");  }