SlideShare une entreprise Scribd logo
1  sur  37
  INHERITANCE
[object Object],[object Object],[object Object]
Types of Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object]
SINGLE INHERITANCE ,[object Object],[object Object],[object Object],A B
When a derived class inherit from multiple base classes it is known as multiple Inheritance. A B C MULTIPLE INHERITANCE Base Class Derived Class
MULTILEVEL INHERITANCE ,[object Object],[object Object],[object Object],[object Object],[object Object],A B C
HYBRID   INHERITANCE ,[object Object],w x y z
HIERARCHICAL INHERITANCE ,[object Object],[object Object],[object Object],a b c d
A general form to defining a derived class is: Class derived class name: visibility mode  base class  name {  members of derived class }  ; Class ABC: public XYZ {  members of ABC };  DEFINING DERIVED CLASS
Example of derived class definition is: Class Sub : public Super   public derivation {  ………  members of sub }; Class Sub: private Super   private derivation { …… ...  members of sub }; Class Sub: protected Super   protected derivation { …… ...  members of sub };
MULTIPLE INHERITANCE Example of derived class definition is: Class derived_class : vis_mode base1, vis_mode base 2 { ………… .  members of derived class }; Class Sub : public SuperA, private SuperB {  ………  members of sub };
Visibility Modes ,[object Object],[object Object],[object Object]
Private Visibility Mode-   The public and protected members of the base class become private members of the derived class. The inherited members can only be accessed only through the member function of derived class. Protected Visibility Mode-   The public and protected members of base class become protected members of the derived class.
Visibility of Inherited base class members in Derived Class. Visibility Mode Public members of base class becomes Protected members of base class becomes Private members of the base class is not accessible to the derived class. Public Public Protected Protected Protected Protected Private Private Private
Accessibility of Base class members  No No Yes Private No Yes Yes Protected Yes Yes Yes Public Accessible from objects outside class Accessible from derived class Accessible from own class Access Specifier
Inheritance and Constructors and Destructors  ,[object Object],[object Object]
Class super  { …… . }; Class Sub : public Super  { ….. }; int main() {  sub ob1; …… . }
Base class Constructors ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class Base { int a;  float b; public : Base(int I, float j) { a = i;  b = j; } … }; Class Derived : public Base {…. Public :  Derived ( int p, float q) : Base (p , q)  {  } }; Even if derived const does not need a parameter, yet it accepts parameter for base const.
Class Base { int a;  float b; public : Base( int i, float j) { a = i;  b = j; } … }; Class Derived : public Base { int x; float y; Public :  Derived ( int i, int j , int p, float q) : Base (p , q)  {  x = i ; Y = j ;  } }; Derived Const is accepting parameter for itself( i ,j) and ( p , q) for Base const
Constructor in Derived Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class gamma: public beta, public alpha { int k; public: gamma(int a,float b, int c): alpha(a) , beta(b) { k=c; } void show() { cout<<“1”<<x<<“2”<<y<<“3”<<k; }}; void main() { gamma g(14,15.2,17); g.show(); }
Facts about inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Abstract class A class that serves only as a base class from which other classes can be derived, but no objects of this base type exist, is known as abstract class.
Constructors in Multiple inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class base2  {  Protected : int b; public : Base2(int y) {  b = y;  cout<<“Constructing Base2”;  } ~Base2 ( ) {  cout<< Destructing Base2 “;  } }; Class derived : public Base2, public Base1 {  int c; public :  derived (int I, int j, int k): Base2(i), Base1(j) { c = k;  cout <<“Constructing Derived”;  }
~ Derived ( ) {  cout << Destructing Derived “;  } Void show( ) {  cout <<“1.”<<a<<“ 2.”<<b <<“ 3.”<<c;  } }; Int main ( ) {  Clrscr(); Derived ob(14,15,16); Ob.show(); } ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Virtual Base class Example  Class Base  {  public : int a ; }; Class D1 : public Base   D1 inherits Base {  public : int b ; }; Class D2 : public Base   D2 inherits Base {  public : int c ; }; Class D3 : public D1, public D2  D3 inherits D1 and D2 {  public :  int total; }; Void main ( ) { D3 ob; ob.a = 25  this is ambiguous Ob.b = 50; Ob.c = 75; Ob.total = ob.a +ob.b + ob.c; Cout <<ob.a<<“”<< ob.b<<“”<< ob.c<<“”<< ob.total<<“”<<“”; }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Remedy
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Void main ( ) { D3 ob; ob.a = 25   now unambiguous Ob.b = 50; Ob.c = 75; Ob.total = ob.a +ob.b + ob.c; Cout <<ob.a<<“”<< ob.b<<“”<< ob.c<<“”<< ob.total<<“”<<“”; }
Example of Multilevel Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
class test: public student {   protected:   float sub1;   float sub2;   public:   void getmarks()   {   cout<<&quot;enter the marks of sub1,sub2&quot;;   cin>>sub1>>sub2;   }   void putmarks()   {   cout<<&quot;marks in sub1=&quot;<<sub1;   cout<<&quot;marks in sub2=&quot;<<sub2;   } };
class result : public test {   float total;   public:   void display(void)   {    total=sub1+sub2;   putnumber();   putmarks();   cout<<&quot;Total&quot;<<total;   }   };   void main()   {   result a;   a.get_number();   a.getmarks();   a.display();   }
  ANY QUERY   THANK YOU

Contenu connexe

Tendances

Inheritance
InheritanceInheritance
InheritanceTech_MX
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCEVenugopalavarma Raja
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++Laxman Puri
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending ClassesNilesh Dalvi
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.MASQ Technologies
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...Simplilearn
 
Multi level inheritence
Multi level inheritenceMulti level inheritence
Multi level inheritenceRanaMOIN1
 
Hybrid inheritance
Hybrid inheritanceHybrid inheritance
Hybrid inheritancezindadili
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingBurhan Ahmed
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Liju Thomas
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classesasadsardar
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Java Inheritance
Java InheritanceJava Inheritance
Java InheritanceVINOTH R
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vineeta Garg
 

Tendances (20)

Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Inheritance
InheritanceInheritance
Inheritance
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 
Multi level inheritence
Multi level inheritenceMulti level inheritence
Multi level inheritence
 
Hybrid inheritance
Hybrid inheritanceHybrid inheritance
Hybrid inheritance
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classes
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 

En vedette (20)

Inheritance
InheritanceInheritance
Inheritance
 
C++ Inheritance
C++ InheritanceC++ Inheritance
C++ Inheritance
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Inheritance, Object Oriented Programming
Inheritance, Object Oriented ProgrammingInheritance, Object Oriented Programming
Inheritance, Object Oriented Programming
 
Inheritance
InheritanceInheritance
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...
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritance
 
Hybrid Inheritance in C++
Hybrid Inheritance in C++Hybrid Inheritance in C++
Hybrid Inheritance in C++
 
Multi level hierarchy
Multi level hierarchyMulti level hierarchy
Multi level hierarchy
 
Genetics pedigree problems
Genetics pedigree problemsGenetics pedigree problems
Genetics pedigree problems
 
Basis of Genetic Inheritance
Basis of Genetic InheritanceBasis of Genetic Inheritance
Basis of Genetic Inheritance
 
Pedigree Basics!
Pedigree Basics!Pedigree Basics!
Pedigree Basics!
 
Pedigree analysis
Pedigree analysisPedigree analysis
Pedigree analysis
 
THE LAWS OF MENDEL
THE LAWS OF MENDELTHE LAWS OF MENDEL
THE LAWS OF MENDEL
 
Inheritance
InheritanceInheritance
Inheritance
 
pedigree analysis
 pedigree analysis pedigree analysis
pedigree analysis
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 

Similaire à Inheritance

lecture-2021inheritance-160705095417.pdf
lecture-2021inheritance-160705095417.pdflecture-2021inheritance-160705095417.pdf
lecture-2021inheritance-160705095417.pdfAneesAbbasi14
 
MODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerMODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerssuser6f3c8a
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxurvashipundir04
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optdeepakskb2013
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphismFALLEE31188
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++RAJ KUMAR
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdfstudy material
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++Shweta Shah
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple InheritanceBhavyaJain137
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritancebunnykhan
 

Similaire à Inheritance (20)

inhertance c++
inhertance c++inhertance c++
inhertance c++
 
lecture-2021inheritance-160705095417.pdf
lecture-2021inheritance-160705095417.pdflecture-2021inheritance-160705095417.pdf
lecture-2021inheritance-160705095417.pdf
 
[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance
 
MODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerMODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computer
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
Lab3
Lab3Lab3
Lab3
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Inheritance and Interfaces
Inheritance and InterfacesInheritance and Interfaces
Inheritance and Interfaces
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
 

Plus de poonam.rwalia

Plus de poonam.rwalia (7)

1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Computer Ethics
Computer EthicsComputer Ethics
Computer Ethics
 
IT
ITIT
IT
 
Benefits Of Computer Software
Benefits Of Computer SoftwareBenefits Of Computer Software
Benefits Of Computer Software
 
Internet
InternetInternet
Internet
 
GIS
GISGIS
GIS
 

Dernier

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
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
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
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
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 

Dernier (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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 ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
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...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

Inheritance

  • 2.
  • 3.
  • 4.
  • 5. When a derived class inherit from multiple base classes it is known as multiple Inheritance. A B C MULTIPLE INHERITANCE Base Class Derived Class
  • 6.
  • 7.
  • 8.
  • 9. A general form to defining a derived class is: Class derived class name: visibility mode base class name { members of derived class } ; Class ABC: public XYZ { members of ABC }; DEFINING DERIVED CLASS
  • 10. Example of derived class definition is: Class Sub : public Super public derivation { ……… members of sub }; Class Sub: private Super private derivation { …… ... members of sub }; Class Sub: protected Super protected derivation { …… ... members of sub };
  • 11. MULTIPLE INHERITANCE Example of derived class definition is: Class derived_class : vis_mode base1, vis_mode base 2 { ………… . members of derived class }; Class Sub : public SuperA, private SuperB { ……… members of sub };
  • 12.
  • 13. Private Visibility Mode- The public and protected members of the base class become private members of the derived class. The inherited members can only be accessed only through the member function of derived class. Protected Visibility Mode- The public and protected members of base class become protected members of the derived class.
  • 14. Visibility of Inherited base class members in Derived Class. Visibility Mode Public members of base class becomes Protected members of base class becomes Private members of the base class is not accessible to the derived class. Public Public Protected Protected Protected Protected Private Private Private
  • 15. Accessibility of Base class members No No Yes Private No Yes Yes Protected Yes Yes Yes Public Accessible from objects outside class Accessible from derived class Accessible from own class Access Specifier
  • 16.
  • 17. Class super { …… . }; Class Sub : public Super { ….. }; int main() { sub ob1; …… . }
  • 18.
  • 19. Class Base { int a; float b; public : Base(int I, float j) { a = i; b = j; } … }; Class Derived : public Base {…. Public : Derived ( int p, float q) : Base (p , q) { } }; Even if derived const does not need a parameter, yet it accepts parameter for base const.
  • 20. Class Base { int a; float b; public : Base( int i, float j) { a = i; b = j; } … }; Class Derived : public Base { int x; float y; Public : Derived ( int i, int j , int p, float q) : Base (p , q) { x = i ; Y = j ; } }; Derived Const is accepting parameter for itself( i ,j) and ( p , q) for Base const
  • 21.
  • 22. Class gamma: public beta, public alpha { int k; public: gamma(int a,float b, int c): alpha(a) , beta(b) { k=c; } void show() { cout<<“1”<<x<<“2”<<y<<“3”<<k; }}; void main() { gamma g(14,15.2,17); g.show(); }
  • 23.
  • 24.
  • 25.
  • 26. Abstract class A class that serves only as a base class from which other classes can be derived, but no objects of this base type exist, is known as abstract class.
  • 27.
  • 28. Class base2 { Protected : int b; public : Base2(int y) { b = y; cout<<“Constructing Base2”; } ~Base2 ( ) { cout<< Destructing Base2 “; } }; Class derived : public Base2, public Base1 { int c; public : derived (int I, int j, int k): Base2(i), Base1(j) { c = k; cout <<“Constructing Derived”; }
  • 29.
  • 30. Virtual Base class Example Class Base { public : int a ; }; Class D1 : public Base D1 inherits Base { public : int b ; }; Class D2 : public Base D2 inherits Base { public : int c ; }; Class D3 : public D1, public D2 D3 inherits D1 and D2 { public : int total; }; Void main ( ) { D3 ob; ob.a = 25 this is ambiguous Ob.b = 50; Ob.c = 75; Ob.total = ob.a +ob.b + ob.c; Cout <<ob.a<<“”<< ob.b<<“”<< ob.c<<“”<< ob.total<<“”<<“”; }
  • 31.
  • 32.
  • 33. Void main ( ) { D3 ob; ob.a = 25 now unambiguous Ob.b = 50; Ob.c = 75; Ob.total = ob.a +ob.b + ob.c; Cout <<ob.a<<“”<< ob.b<<“”<< ob.c<<“”<< ob.total<<“”<<“”; }
  • 34.
  • 35. class test: public student { protected: float sub1; float sub2; public: void getmarks() { cout<<&quot;enter the marks of sub1,sub2&quot;; cin>>sub1>>sub2; } void putmarks() { cout<<&quot;marks in sub1=&quot;<<sub1; cout<<&quot;marks in sub2=&quot;<<sub2; } };
  • 36. class result : public test { float total; public: void display(void) { total=sub1+sub2; putnumber(); putmarks(); cout<<&quot;Total&quot;<<total; } }; void main() { result a; a.get_number(); a.getmarks(); a.display(); }
  • 37. ANY QUERY THANK YOU