SlideShare a Scribd company logo
INHERITANCE
By – Preeti Rawat
Class – BCA 2nd Sem
CLASS & OBJECTS
 Class is a blueprint or template of an object.
 It is a user – defined datatype that has data
members & member functions.
 Objects are real world entity or instance of class,
such as pen , laptop, mobile, chair etc.
 We define a class using the keyword “class”.
 Syntax :
class class_name{
//data_members
//member_functions
};
 There are four fundamentals of OOPs which
are:
1. Inheritance
2. Abstraction
3. Polymorphism
4. Encapsulation
FUNDAMENTALS OF OOPS
 Inheritance is the capability of one class to inherit
properties from another class.
 This process of creating new classes from the existing
class is called inheritance.
 The class whose property is inherited is called the Base
Class or Super-Class or Parent Class.
 The class who inherits the property is called the Derived
Class or Sub-Class or Child Class.
INTRODUCTION TO INHERITANCE
 Syntax:
class base_class_name{
//data_members
//member_functions
};
class derived_class_name: access_specifier
base_class_name {
//data_members
//member_functions
};
PROGRAM
class rectangle{
protected:
float l,b;
public:
void get(float x,float y){
l=x;
b=y; }
void area(){
cout<<"Area = "<<l*b<<endl;}
};
class cuboid: public rectangle {
float h;
public:
void height(float z){
h=z; }
void volume(){
cout<<"Volume= "<<l*b*h<<endl; }
};
PRIVATE & PROTECTED MEMBERS
 Private members cannot be inherited by the
derived class.
 Only protected and public members can be
accessed by member functions of its own class and
in any class derived from its own class.
 Protected members can’t be accessed from
function outside these classes.
1. Single Inheritance
2. Multiple Inheritance
3. Multi-level Inheritance
4. Hierarchical Inheritance
5. Hybrid Inheritance
TYPES OF INHERITANCE
SINGLE INHERITANCE
 Derivation of a class from only one base class is
called Single Inheritance.
 Syntax:
class base_class_name{
//data_members
//member_functions
};
class derived_class_name: access_specifier
base_class_name {
//data_members
//member_functions
};
Base
Class
Derived
Class
MULTIPLE INHERITANCE
 Here, the derived class is derive from more than one base
classes, called Multiple Inheritance.
 Syntax:
class derived_class: access_specifier base_class1,
access_specifier base_class2,… access_specifier
base_classn {
//Data_members & Member_functions
};
 Example-
class A{
//Data_members & Member_functions };
class B{
//Data_members & Member_functions };
class C: public A, public B{
//Data_members & Member_functions };
A B
C
MULTI-LEVEL INHERITANCE
 When a sub-class is derived from a base class
which itself is derived from another class, it is
known as Multi-level Inheritance.
 Example:
X
Y
Z
 Syntax:
class base_class{
//Data members & Member Function
};
class derived_class1: access_specifier
base_class {
//Data members & Member Function
};
class derived_class2: access_specifier
derived_class1 {
//Data members & Member Function
};
HIERARCHICAL INHERITANCE
 Derivation of many classes from single base class
is called Hierarchical Inheritance.
 Example:
Y Z
X
 Syntax:
class base_class{
//Data members & Member Function
};
class derived_class1: access_specifier {
//Data members & Member Function
};
class derived_class2: access_specifier base_class{
//Data members & Member Function
};
HYBRID INHERITANCE
 Derivation of a class involving more than one form
of Inheritance (i.e. Single Inheritance, Multiple
inheritance, Multi-Level Inheritance or
Hierarchical Inheritance), is known as Hybrid
Inheritance.
 Example:
A
C
B D
Single Inheritance
Multi-level Inheritance
Multiple Inheritance
Hierarchical Inheritance
Any Query??

More Related Content

Similar to Inheritance.pptx

Inheritance
InheritanceInheritance
Inheritance
prashant prath
 
Mca 2nd sem u-3 inheritance
Mca 2nd  sem u-3 inheritanceMca 2nd  sem u-3 inheritance
Mca 2nd sem u-3 inheritance
Rai University
 
Bca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritanceBca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritance
Rai University
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
Prem Kumar Badri
 
Inheritance
InheritanceInheritance
Inheritance
Munsif Ullah
 
inheritance
inheritanceinheritance
inheritance
Amir_Mukhtar
 
Inheritance
Inheritance Inheritance
Inheritance
sourav verma
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
SadiqullahGhani1
 
week14 (1).ppt
week14 (1).pptweek14 (1).ppt
week14 (1).ppt
amal68766
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
MASQ Technologies
 
Inheritance
InheritanceInheritance
Inheritance
Pranali Chaudhari
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
classall
 
session 24_Inheritance.ppt
session 24_Inheritance.pptsession 24_Inheritance.ppt
session 24_Inheritance.ppt
NAVANEETCHATURVEDI2
 
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
 
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 in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
Hirra Sultan
 
Inheritance
InheritanceInheritance
Inheritance
Aadhi Aadhithya
 
Oop
OopOop
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
TharuniDiddekunta
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
Shweta Shah
 

Similar to Inheritance.pptx (20)

Inheritance
InheritanceInheritance
Inheritance
 
Mca 2nd sem u-3 inheritance
Mca 2nd  sem u-3 inheritanceMca 2nd  sem u-3 inheritance
Mca 2nd sem u-3 inheritance
 
Bca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritanceBca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritance
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
inheritance
inheritanceinheritance
inheritance
 
Inheritance
Inheritance Inheritance
Inheritance
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
week14 (1).ppt
week14 (1).pptweek14 (1).ppt
week14 (1).ppt
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
Inheritance
InheritanceInheritance
Inheritance
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
session 24_Inheritance.ppt
session 24_Inheritance.pptsession 24_Inheritance.ppt
session 24_Inheritance.ppt
 
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
 
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 in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Inheritance
InheritanceInheritance
Inheritance
 
Oop
OopOop
Oop
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 

Recently uploaded

Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
ramrag33
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
IJECEIAES
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
bijceesjournal
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 

Recently uploaded (20)

Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 

Inheritance.pptx

  • 1. INHERITANCE By – Preeti Rawat Class – BCA 2nd Sem
  • 2. CLASS & OBJECTS  Class is a blueprint or template of an object.  It is a user – defined datatype that has data members & member functions.  Objects are real world entity or instance of class, such as pen , laptop, mobile, chair etc.  We define a class using the keyword “class”.  Syntax : class class_name{ //data_members //member_functions };
  • 3.  There are four fundamentals of OOPs which are: 1. Inheritance 2. Abstraction 3. Polymorphism 4. Encapsulation FUNDAMENTALS OF OOPS
  • 4.  Inheritance is the capability of one class to inherit properties from another class.  This process of creating new classes from the existing class is called inheritance.  The class whose property is inherited is called the Base Class or Super-Class or Parent Class.  The class who inherits the property is called the Derived Class or Sub-Class or Child Class. INTRODUCTION TO INHERITANCE
  • 5.  Syntax: class base_class_name{ //data_members //member_functions }; class derived_class_name: access_specifier base_class_name { //data_members //member_functions };
  • 6. PROGRAM class rectangle{ protected: float l,b; public: void get(float x,float y){ l=x; b=y; } void area(){ cout<<"Area = "<<l*b<<endl;} }; class cuboid: public rectangle { float h; public: void height(float z){ h=z; } void volume(){ cout<<"Volume= "<<l*b*h<<endl; } };
  • 7. PRIVATE & PROTECTED MEMBERS  Private members cannot be inherited by the derived class.  Only protected and public members can be accessed by member functions of its own class and in any class derived from its own class.  Protected members can’t be accessed from function outside these classes.
  • 8. 1. Single Inheritance 2. Multiple Inheritance 3. Multi-level Inheritance 4. Hierarchical Inheritance 5. Hybrid Inheritance TYPES OF INHERITANCE
  • 9. SINGLE INHERITANCE  Derivation of a class from only one base class is called Single Inheritance.  Syntax: class base_class_name{ //data_members //member_functions }; class derived_class_name: access_specifier base_class_name { //data_members //member_functions }; Base Class Derived Class
  • 10. MULTIPLE INHERITANCE  Here, the derived class is derive from more than one base classes, called Multiple Inheritance.  Syntax: class derived_class: access_specifier base_class1, access_specifier base_class2,… access_specifier base_classn { //Data_members & Member_functions };  Example- class A{ //Data_members & Member_functions }; class B{ //Data_members & Member_functions }; class C: public A, public B{ //Data_members & Member_functions }; A B C
  • 11. MULTI-LEVEL INHERITANCE  When a sub-class is derived from a base class which itself is derived from another class, it is known as Multi-level Inheritance.  Example: X Y Z
  • 12.  Syntax: class base_class{ //Data members & Member Function }; class derived_class1: access_specifier base_class { //Data members & Member Function }; class derived_class2: access_specifier derived_class1 { //Data members & Member Function };
  • 13. HIERARCHICAL INHERITANCE  Derivation of many classes from single base class is called Hierarchical Inheritance.  Example: Y Z X
  • 14.  Syntax: class base_class{ //Data members & Member Function }; class derived_class1: access_specifier { //Data members & Member Function }; class derived_class2: access_specifier base_class{ //Data members & Member Function };
  • 15. HYBRID INHERITANCE  Derivation of a class involving more than one form of Inheritance (i.e. Single Inheritance, Multiple inheritance, Multi-Level Inheritance or Hierarchical Inheritance), is known as Hybrid Inheritance.  Example: A C B D Single Inheritance Multi-level Inheritance Multiple Inheritance Hierarchical Inheritance