SlideShare a Scribd company logo
1 of 17
Download to read offline
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

Similar to inheritance-16031525566nbhij56604452.pdf

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
 

Similar to inheritance-16031525566nbhij56604452.pdf (20)

Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
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
 
inheritance
   inheritance   inheritance
inheritance
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Inheritance in c++ part1
Inheritance in c++ part1Inheritance in c++ part1
Inheritance in c++ part1
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 

More from kashafishfaq21

Registers.pptxmjgfdgjbgghjghjjfyujgftujbvf
Registers.pptxmjgfdgjbgghjghjjfyujgftujbvfRegisters.pptxmjgfdgjbgghjghjjfyujgftujbvf
Registers.pptxmjgfdgjbgghjghjjfyujgftujbvf
kashafishfaq21
 
encapsulation1-150816163959-lva1-app6891.pdf
encapsulation1-150816163959-lva1-app6891.pdfencapsulation1-150816163959-lva1-app6891.pdf
encapsulation1-150816163959-lva1-app6891.pdf
kashafishfaq21
 
HAFIZA PP666666576887654678876544566T.pdf
HAFIZA  PP666666576887654678876544566T.pdfHAFIZA  PP666666576887654678876544566T.pdf
HAFIZA PP666666576887654678876544566T.pdf
kashafishfaq21
 
circuits-150320014416-conversion-gate01.pdf
circuits-150320014416-conversion-gate01.pdfcircuits-150320014416-conversion-gate01.pdf
circuits-150320014416-conversion-gate01.pdf
kashafishfaq21
 
polymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdfpolymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdf
kashafishfaq21
 
logicgates-180511113246666666660 (1).pdf
logicgates-180511113246666666660 (1).pdflogicgates-180511113246666666660 (1).pdf
logicgates-180511113246666666660 (1).pdf
kashafishfaq21
 
babsatu-140703233001-phpapp666666601.pdf
babsatu-140703233001-phpapp666666601.pdfbabsatu-140703233001-phpapp666666601.pdf
babsatu-140703233001-phpapp666666601.pdf
kashafishfaq21
 
ifrad01605545networkcomponents-181123160910.pdf
ifrad01605545networkcomponents-181123160910.pdfifrad01605545networkcomponents-181123160910.pdf
ifrad01605545networkcomponents-181123160910.pdf
kashafishfaq21
 

More from kashafishfaq21 (8)

Registers.pptxmjgfdgjbgghjghjjfyujgftujbvf
Registers.pptxmjgfdgjbgghjghjjfyujgftujbvfRegisters.pptxmjgfdgjbgghjghjjfyujgftujbvf
Registers.pptxmjgfdgjbgghjghjjfyujgftujbvf
 
encapsulation1-150816163959-lva1-app6891.pdf
encapsulation1-150816163959-lva1-app6891.pdfencapsulation1-150816163959-lva1-app6891.pdf
encapsulation1-150816163959-lva1-app6891.pdf
 
HAFIZA PP666666576887654678876544566T.pdf
HAFIZA  PP666666576887654678876544566T.pdfHAFIZA  PP666666576887654678876544566T.pdf
HAFIZA PP666666576887654678876544566T.pdf
 
circuits-150320014416-conversion-gate01.pdf
circuits-150320014416-conversion-gate01.pdfcircuits-150320014416-conversion-gate01.pdf
circuits-150320014416-conversion-gate01.pdf
 
polymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdfpolymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdf
 
logicgates-180511113246666666660 (1).pdf
logicgates-180511113246666666660 (1).pdflogicgates-180511113246666666660 (1).pdf
logicgates-180511113246666666660 (1).pdf
 
babsatu-140703233001-phpapp666666601.pdf
babsatu-140703233001-phpapp666666601.pdfbabsatu-140703233001-phpapp666666601.pdf
babsatu-140703233001-phpapp666666601.pdf
 
ifrad01605545networkcomponents-181123160910.pdf
ifrad01605545networkcomponents-181123160910.pdfifrad01605545networkcomponents-181123160910.pdf
ifrad01605545networkcomponents-181123160910.pdf
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
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
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
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
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

inheritance-16031525566nbhij56604452.pdf

  • 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