SlideShare a Scribd company logo
PREPARED BY :- PAUMIL PATEL
INHERITANCE IN C++
WHAT IS INHERITANCE
 Inheritance is one of the important feature of the OOP.
Inheritance is the method by which objects of one class
gets the properties of another class.
 The mechanism that allows us to extend the
definition of a class without making any physical
changes to the existing class is inheritance.
OVERVIEW OF INHERITANCE
 Inheritance is the capability of one class to acquire
properties and characteristics from another class. The class
whose properties are inherited by other class is called
the Parent or Base or Super class. And, the class which
inherits properties of other class is
called Child or Derived or Sub class.
 Inheritance lets you create new classes from existing class.
Any new class that you create from an existing class is
called derived class; existing class is called base class.
ADVANTAGES OF INHERITANCE
 Sometimes we need to repeat the code or we need
repeat the whole class properties. So It helps in
various ways.
1.) It saves memory space.
2.) It saves time.
3.) It will remove frustration.
4.) It increases reliability of the code
5.) It saves the developing and testing efforts
WHY WE USE INHERITANCE?
To increase the reusability of the code
and to make further usable for another
classes. We use the concept of
inheritance.
EXAMPLE OF INHERITANCE
BASIC SYNTAX OF INHERITANCE
 class Subclass_name : access mode Superclass_name
 While defining a subclass like this, the super class(base
class)must be already defined or at least declared before the
subclass(derived class) declaration.
 Access Mode is used to specify, the mode in which the
properties of superclass will be inherited into subclass, public,
private or protected.
FORMS OF INHERITANCE
SINGLE INHERITANCE
 In single level inheritance, there is only one base
class and has only one derived class.
 Example of single level inheritance:
class Base
{
};
class Derv: public Base
{
};
EXAMPLE OF SIMPLE CLASS INHERITANCE
 class Animal
{
public:
int legs = 4;
};
class Dog : public Animal
{
public:
int tail = 1;
};
int main()
{
Dog d;
cout << d.legs;
cout << d.tail;
}
Output : 4 1
MULTIPLE INHERITANCE
 A C++ class can inherit members from more than one class
and here is the extended syntax:
 class derived-class: access baseA, access baseB....
 Where access is one of public, protected, or private and
would be given for every base class and they will be
separated by comma as shown above.
EXAMPLE OF MULTIPLE INHERITANCE
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rno,m1,m2;
public:
void get()
{
cout<<"Enter the Roll no :";
cin>>rno;
cout<<"Enter the two marks :";
cin>>m1>>m2;
}
};
class sports
{
protected:
int sm; // sm = Sports mark
public:
void getsm()
{
cout<<"nEnter the sports mark :";
cin>>sm;
}
};
class statement:public student,public sports
{
int tot,avg;
public:
void display()
{
tot=(m1+m2+sm);
avg=tot/3;
cout<<"nntRoll No : "<<rno<<"ntTotal : "<<tot;
cout<<"ntAverage : "<<avg;
}
void main()
{
clrscr();
statement obj;
obj.get();
obj.getsm();
obj.display();
getch();
}
Output:
Enter the Roll no: 100
Enter two marks
90
80
Enter the Sports Mark: 90
Roll No: 100
Total : 260
Average: 86.66
REFERENCES
 http://www.cpp.thiyagaraaj.com/c-programs/simple-
program-for-multiple-inheritance-using-c-
programming
 http://www.studytonight.com/cpp/overview-of-
inheritance.php
 http://www.tutorialspoint.com/cplusplus/cpp_inherita
nce.html
 http://www.cplusplus.com/doc/tutorial/inheritance/
THANK YOU 

More Related Content

What's hot

07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
Haresh Jaiswal
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
HarshitaAshwani
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
MASQ Technologies
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
Ritika Sharma
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
Sanjit Shaw
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
Method overriding
Method overridingMethod overriding
Method overriding
Azaz Maverick
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
harsh kothari
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
Boopathi K
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++Tech_MX
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
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
Venugopalavarma Raja
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
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
 

What's hot (20)

07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
Method overriding
Method overridingMethod overriding
Method overriding
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
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
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
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...
 

Viewers also liked

Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
Laxman Puri
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
Muraleedhar Sundararajan
 
Inheritance
InheritanceInheritance
InheritanceTech_MX
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++
HalaiHansaika
 
Programming in c++
Programming in c++Programming in c++
Programming in c++Baljit Saini
 
C# Generics
C# GenericsC# Generics
C# Generics
Rohit Vipin Mathews
 
Lexical analysis
Lexical analysisLexical analysis
Lexical analysis
Richa Sharma
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
sanya6900
 
Bca ii dfs u-4 sorting and searching structure
Bca ii dfs u-4 sorting and searching structureBca ii dfs u-4 sorting and searching structure
Bca ii dfs u-4 sorting and searching structure
Rai University
 
Nice PPTs
Nice PPTsNice PPTs
Nice PPTs
Harry Smiles
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
Amritsinghmehra
 
Searching and Sorting
Searching and SortingSearching and Sorting
Searching and Sorting
Forrester High School
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
Rosie Jane Enomar
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueGhaffar Khan
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
Multiple Inheritance For C++
Multiple Inheritance For C++Multiple Inheritance For C++
Multiple Inheritance For C++elliando dias
 

Viewers also liked (19)

Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
 
C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
 
C# Generics
C# GenericsC# Generics
C# Generics
 
Lexical analysis
Lexical analysisLexical analysis
Lexical analysis
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
Bca ii dfs u-4 sorting and searching structure
Bca ii dfs u-4 sorting and searching structureBca ii dfs u-4 sorting and searching structure
Bca ii dfs u-4 sorting and searching structure
 
Nice PPTs
Nice PPTsNice PPTs
Nice PPTs
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Searching and Sorting
Searching and SortingSearching and Sorting
Searching and Sorting
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, Queue
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Multiple Inheritance For C++
Multiple Inheritance For C++Multiple Inheritance For C++
Multiple Inheritance For C++
 

Similar to Inheritance in c++

Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
preetirawat242004
 
INHERITANCE.pptx
INHERITANCE.pptxINHERITANCE.pptx
INHERITANCE.pptx
HARIPRIYA M P
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Ariful Islam
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
WaqarRaj1
 
EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++
Nikunj Patel
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
TharuniDiddekunta
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
Final presentation programming
Final presentation programmingFinal presentation programming
Final presentation programming
haider ali
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
sushamaGavarskar1
 
Inheritance in Java.pdf
Inheritance in Java.pdfInheritance in Java.pdf
Inheritance in Java.pdf
kumari36
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritance
mcollison
 
Inheritance
InheritanceInheritance
Inheritance
SangeethaSasi1
 
Concept of OOPS with real life examples
Concept of OOPS with real life examplesConcept of OOPS with real life examples
Concept of OOPS with real life examples
Neha Sharma
 
INHERITANCE-Oopc ppt-ta4
INHERITANCE-Oopc ppt-ta4INHERITANCE-Oopc ppt-ta4
INHERITANCE-Oopc ppt-ta4
Ashutosh Makwana
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
RudranilDas11
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
 
C++ Inheritance.pptx
C++ Inheritance.pptxC++ Inheritance.pptx
C++ Inheritance.pptx
XanGwaps
 
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
itxminahil29
 
Inheritance
InheritanceInheritance
Inheritance
Amit Dixit
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
NITHISG1
 

Similar to Inheritance in c++ (20)

Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
INHERITANCE.pptx
INHERITANCE.pptxINHERITANCE.pptx
INHERITANCE.pptx
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Final presentation programming
Final presentation programmingFinal presentation programming
Final presentation programming
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
 
Inheritance in Java.pdf
Inheritance in Java.pdfInheritance in Java.pdf
Inheritance in Java.pdf
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Concept of OOPS with real life examples
Concept of OOPS with real life examplesConcept of OOPS with real life examples
Concept of OOPS with real life examples
 
INHERITANCE-Oopc ppt-ta4
INHERITANCE-Oopc ppt-ta4INHERITANCE-Oopc ppt-ta4
INHERITANCE-Oopc ppt-ta4
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
 
C++ Inheritance.pptx
C++ Inheritance.pptxC++ Inheritance.pptx
C++ Inheritance.pptx
 
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
 
Inheritance
InheritanceInheritance
Inheritance
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
 

Recently uploaded

HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 

Recently uploaded (20)

HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 

Inheritance in c++

  • 1. PREPARED BY :- PAUMIL PATEL INHERITANCE IN C++
  • 2. WHAT IS INHERITANCE  Inheritance is one of the important feature of the OOP. Inheritance is the method by which objects of one class gets the properties of another class.  The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is inheritance.
  • 3. OVERVIEW OF INHERITANCE  Inheritance is the capability of one class to acquire properties and characteristics from another class. The class whose properties are inherited by other class is called the Parent or Base or Super class. And, the class which inherits properties of other class is called Child or Derived or Sub class.  Inheritance lets you create new classes from existing class. Any new class that you create from an existing class is called derived class; existing class is called base class.
  • 4. ADVANTAGES OF INHERITANCE  Sometimes we need to repeat the code or we need repeat the whole class properties. So It helps in various ways. 1.) It saves memory space. 2.) It saves time. 3.) It will remove frustration. 4.) It increases reliability of the code 5.) It saves the developing and testing efforts
  • 5. WHY WE USE INHERITANCE? To increase the reusability of the code and to make further usable for another classes. We use the concept of inheritance.
  • 7. BASIC SYNTAX OF INHERITANCE  class Subclass_name : access mode Superclass_name  While defining a subclass like this, the super class(base class)must be already defined or at least declared before the subclass(derived class) declaration.  Access Mode is used to specify, the mode in which the properties of superclass will be inherited into subclass, public, private or protected.
  • 8.
  • 10. SINGLE INHERITANCE  In single level inheritance, there is only one base class and has only one derived class.  Example of single level inheritance: class Base { }; class Derv: public Base { };
  • 11. EXAMPLE OF SIMPLE CLASS INHERITANCE  class Animal { public: int legs = 4; }; class Dog : public Animal { public: int tail = 1; }; int main() { Dog d; cout << d.legs; cout << d.tail; } Output : 4 1
  • 12. MULTIPLE INHERITANCE  A C++ class can inherit members from more than one class and here is the extended syntax:  class derived-class: access baseA, access baseB....  Where access is one of public, protected, or private and would be given for every base class and they will be separated by comma as shown above.
  • 13. EXAMPLE OF MULTIPLE INHERITANCE #include<iostream.h> #include<conio.h> class student { protected: int rno,m1,m2; public: void get() { cout<<"Enter the Roll no :"; cin>>rno; cout<<"Enter the two marks :"; cin>>m1>>m2; } };
  • 14. class sports { protected: int sm; // sm = Sports mark public: void getsm() { cout<<"nEnter the sports mark :"; cin>>sm; } }; class statement:public student,public sports { int tot,avg; public: void display() { tot=(m1+m2+sm); avg=tot/3; cout<<"nntRoll No : "<<rno<<"ntTotal : "<<tot; cout<<"ntAverage : "<<avg; }
  • 15. void main() { clrscr(); statement obj; obj.get(); obj.getsm(); obj.display(); getch(); } Output: Enter the Roll no: 100 Enter two marks 90 80 Enter the Sports Mark: 90 Roll No: 100 Total : 260 Average: 86.66