SlideShare a Scribd company logo
8
Most read
11
Most read
14
Most read
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.
Inheritance in c++
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 (20)

PPTX
Virtual base class
Tech_MX
 
PPT
Class and object in C++
rprajat007
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PPTX
Pure virtual function and abstract class
Amit Trivedi
 
PDF
Operator overloading C++
Lahiru Dilshan
 
PPTX
Abstract class in c++
Sujan Mia
 
PPTX
Inheritance in c++
Vineeta Garg
 
PPTX
Inheritance in c++
Vishal Patil
 
PPTX
Member Function in C++
NikitaKaur10
 
PPTX
Inheritance in oops
Hirra Sultan
 
PPTX
Access specifier
zindadili
 
PPTX
Polymorphism In c++
Vishesh Jha
 
PPTX
Constructors and Destructor in C++
International Institute of Information Technology (I²IT)
 
PPTX
Templates in c++
ThamizhselviKrishnam
 
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
PPTX
Inheritance ppt
Nivegeetha
 
PDF
Classes and objects
Nilesh Dalvi
 
PPTX
Functions in c++
Rokonuzzaman Rony
 
PPTX
class and objects
Payel Guria
 
PPTX
Inheritance in java
RahulAnanda1
 
Virtual base class
Tech_MX
 
Class and object in C++
rprajat007
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
Pure virtual function and abstract class
Amit Trivedi
 
Operator overloading C++
Lahiru Dilshan
 
Abstract class in c++
Sujan Mia
 
Inheritance in c++
Vineeta Garg
 
Inheritance in c++
Vishal Patil
 
Member Function in C++
NikitaKaur10
 
Inheritance in oops
Hirra Sultan
 
Access specifier
zindadili
 
Polymorphism In c++
Vishesh Jha
 
Templates in c++
ThamizhselviKrishnam
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Inheritance ppt
Nivegeetha
 
Classes and objects
Nilesh Dalvi
 
Functions in c++
Rokonuzzaman Rony
 
class and objects
Payel Guria
 
Inheritance in java
RahulAnanda1
 

Viewers also liked (20)

PPTX
Inheritance in C++
Laxman Puri
 
PPT
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
cprogrammings
 
PPTX
inheritance c++
Muraleedhar Sundararajan
 
PPTX
Inheritance
Tech_MX
 
PPTX
Templates in C++
Tech_MX
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
PPTX
Tokens expressionsin C++
HalaiHansaika
 
PDF
Programming in c++
Baljit Saini
 
PPT
C++ Interview Questions
Kaushik Raghupathi
 
PPTX
C# Generics
Rohit Vipin Mathews
 
PDF
Lexical analysis
Richa Sharma
 
PPT
Templates exception handling
sanya6900
 
PPTX
Bca ii dfs u-4 sorting and searching structure
Rai University
 
PPS
Nice PPTs
Harry Smiles
 
PPTX
OOPS IN C++
Amritsinghmehra
 
PPT
Searching and Sorting
Forrester High School
 
PDF
Java Inheritance
Rosie Jane Enomar
 
PPT
Java inheritance
Arati Gadgil
 
PPT
Introductiont To Aray,Tree,Stack, Queue
Ghaffar Khan
 
PPTX
Inheritance in java
Tech_MX
 
Inheritance in C++
Laxman Puri
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
cprogrammings
 
inheritance c++
Muraleedhar Sundararajan
 
Inheritance
Tech_MX
 
Templates in C++
Tech_MX
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
Tokens expressionsin C++
HalaiHansaika
 
Programming in c++
Baljit Saini
 
C++ Interview Questions
Kaushik Raghupathi
 
C# Generics
Rohit Vipin Mathews
 
Lexical analysis
Richa Sharma
 
Templates exception handling
sanya6900
 
Bca ii dfs u-4 sorting and searching structure
Rai University
 
Nice PPTs
Harry Smiles
 
OOPS IN C++
Amritsinghmehra
 
Searching and Sorting
Forrester High School
 
Java Inheritance
Rosie Jane Enomar
 
Java inheritance
Arati Gadgil
 
Introductiont To Aray,Tree,Stack, Queue
Ghaffar Khan
 
Inheritance in java
Tech_MX
 
Ad

Similar to Inheritance in c++ (20)

PPTX
Introduction to inheritance and different types of inheritance
huzaifaakram12
 
PPT
Inheritance.ppt
JP2B1197685ARamSaiPM
 
PPT
6 Inheritance
Praveen M Jigajinni
 
PDF
lecture 6.pdf
WaqarRaj1
 
PPTX
Inheritance
zindadili
 
PPTX
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
 
PPTX
Inheritance
Burhan Ahmed
 
PPSX
Inheritance and Polymorphism in Oops
LalfakawmaKh
 
DOCX
oop database doc for studevsgdy fdsyn hdf
itxminahil29
 
PPT
Lec5.ppt
CharlesAsiedu4
 
PPTX
Inheritance in C++ (Programming Fundamentals)
Home
 
PPTX
Inheritance in c++ by Manan Pasricha
MananPasricha
 
PPTX
Inheritance
SangeethaSasi1
 
PPT
Inheritance and its types explained.ppt
SarthakKumar93
 
PPT
Inheritance in C++
Shweta Shah
 
PDF
Inheritance
Prof. Dr. K. Adisesha
 
PPTX
Inheritance
prashant prath
 
PDF
INHERITANCE
RohitK71
 
PDF
c++Inheritance.pdf
RanjanaThakuria1
 
PPTX
Inheritance.pptx
Tansh5
 
Introduction to inheritance and different types of inheritance
huzaifaakram12
 
Inheritance.ppt
JP2B1197685ARamSaiPM
 
6 Inheritance
Praveen M Jigajinni
 
lecture 6.pdf
WaqarRaj1
 
Inheritance
zindadili
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
 
Inheritance
Burhan Ahmed
 
Inheritance and Polymorphism in Oops
LalfakawmaKh
 
oop database doc for studevsgdy fdsyn hdf
itxminahil29
 
Lec5.ppt
CharlesAsiedu4
 
Inheritance in C++ (Programming Fundamentals)
Home
 
Inheritance in c++ by Manan Pasricha
MananPasricha
 
Inheritance
SangeethaSasi1
 
Inheritance and its types explained.ppt
SarthakKumar93
 
Inheritance in C++
Shweta Shah
 
Inheritance
prashant prath
 
INHERITANCE
RohitK71
 
c++Inheritance.pdf
RanjanaThakuria1
 
Inheritance.pptx
Tansh5
 
Ad

Recently uploaded (20)

PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
PPTX
ETP Presentation(1000m3 Small ETP For Power Plant and industry
MD Azharul Islam
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
All chapters of Strength of materials.ppt
girmabiniyam1234
 
PDF
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
PDF
Air -Powered Car PPT by ER. SHRESTH SUDHIR KOKNE.pdf
SHRESTHKOKNE
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PPTX
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
Jual GPS Geodetik CHCNAV i93 IMU-RTK Lanjutan dengan Survei Visual
Budi Minds
 
PPTX
Introduction to Fluid and Thermal Engineering
Avesahemad Husainy
 
PPTX
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
PDF
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
Inventory management chapter in automation and robotics.
atisht0104
 
Information Retrieval and Extraction - Module 7
premSankar19
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
ETP Presentation(1000m3 Small ETP For Power Plant and industry
MD Azharul Islam
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
All chapters of Strength of materials.ppt
girmabiniyam1234
 
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
Air -Powered Car PPT by ER. SHRESTH SUDHIR KOKNE.pdf
SHRESTHKOKNE
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
Jual GPS Geodetik CHCNAV i93 IMU-RTK Lanjutan dengan Survei Visual
Budi Minds
 
Introduction to Fluid and Thermal Engineering
Avesahemad Husainy
 
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 

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.
  • 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
  • 16. 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/