SlideShare a Scribd company logo
PresentationPresentation
OOPOOP
Author:Author:
Asad-Ur-RehmanAsad-Ur-Rehman
Inheritance: ExtendingInheritance: Extending
ClassesClasses
IntroductionIntroduction
 Reusability is an important feature ofReusability is an important feature of
OOP.OOP.
 C++ strongly supports the conceptC++ strongly supports the concept
of reusability.of reusability.
IntroductionIntroduction
 The mechanism of deriving a newThe mechanism of deriving a new
class from an old one is calledclass from an old one is called
inheritance (or derivation).inheritance (or derivation).
 The old class is referred to as baseThe old class is referred to as base
class.( superclass, parent)class.( superclass, parent)
 The new class is called the derivedThe new class is called the derived
class or subclass.(child)class or subclass.(child)
continue …
IntroductionIntroduction
 The derived class inherits some or allThe derived class inherits some or all
of the attributes and functions fromof the attributes and functions from
the base class.the base class.
 A class can also inherit propertiesA class can also inherit properties
from more than one class or fromfrom more than one class or from
more than one level.more than one level.
continue …
Single InheritanceSingle Inheritance
 A derived class with only one baseA derived class with only one base
class.class.
A
B
Multiple InheritanceMultiple Inheritance
 A derived class with several baseA derived class with several base
classes.classes.
A
C
B
Multilevel InheritanceMultilevel Inheritance
 The mechanism of deriving a classThe mechanism of deriving a class
from another derived class.from another derived class.
A
C
B
Derived ClassesDerived Classes
 A derived class can be defined byA derived class can be defined by
specifying its relationship with thespecifying its relationship with the
base class in addition to its ownbase class in addition to its own
details.details.
classclass derived-class-namederived-class-name :: visibility-modevisibility-mode base-class-namebase-class-name
{{
………………////
………………// members of derived class// members of derived class
………………////
};};
Derived ClassesDerived Classes
classclass derived-class-namederived-class-name :: visibility-modevisibility-mode base-class-namebase-class-name
{{
………………////
………………// members of derived class// members of derived class
………………////
};};
The colon indicates that the
derived-class-name is derived
from the base-class-name
The visibility mode is
optional and , if
present, may be either
private or public.
The default visibility
mode is private.
Visibility mode specifies
whether the features of
the base class are
derived privately or
publicly.
continue …
Derived ClassesDerived Classes
 When a base class is privately derived by aWhen a base class is privately derived by a
derived class, “public members” of the base classderived class, “public members” of the base class
become “private members” of the derived class.become “private members” of the derived class.
 Therefore the members of the derived class canTherefore the members of the derived class can
only access the public members of the base class.only access the public members of the base class.
 They are inaccessible to the objects of theThey are inaccessible to the objects of the
derived class.derived class.
 No member of the base class is accessible to theNo member of the base class is accessible to the
objects of the derived class.objects of the derived class.
continue …
Derived ClassesDerived Classes
 When a base class is publicly inherited,When a base class is publicly inherited,
”public members” of the base class”public members” of the base class
become the “public members” of thebecome the “public members” of the
derived class.derived class.
 They are accessible to the objects of theThey are accessible to the objects of the
derived class.derived class.
continue …
Derived ClassesDerived Classes
 The private members of the base class areThe private members of the base class are
not inherited in both the casesnot inherited in both the cases
(publicly/privately inherited).(publicly/privately inherited).
 The private members of a base class willThe private members of a base class will
never become the members of its derivednever become the members of its derived
class.class.
continue …
InheritanceInheritance
 In inheritance, some of the base class dataIn inheritance, some of the base class data
elements and member functions are inherited intoelements and member functions are inherited into
the derived class.the derived class.
 We can add our own data and member functionsWe can add our own data and member functions
for extending the functionality of the base class.for extending the functionality of the base class.
 It is a powerful tool for incremental programIt is a powerful tool for incremental program
development.development.
Effect of Inheritance on the visibility of MembersEffect of Inheritance on the visibility of Members
Private
Protected
Public
Private
Protected
Public
Private
Protected
Private
Protected
Public Public
Not inheritableNot inheritable
Class B
Class D1 : public B Class D2 : private B
Class X : public D1, protected D2
VisibilityVisibility
Base classBase class
visibilityvisibility
Derived class visibilityDerived class visibility
PublicPublic
DerivationDerivation
PrivatePrivate
DerivationDerivation
ProtectedProtected
DerivationDerivation
PrivatePrivate  NotNot
InheritedInherited
NotNot
InheritedInherited
NotNot
InheritedInherited
ProtectedProtected  ProtectedProtected PrivatePrivate ProtectedProtected
PublicPublic  PublicPublic PrivatePrivate ProtectedProtected
class Shapeclass Shape
{{
protected:protected:
float width, height;float width, height;
public:public:
void set data (float a, float b)void set data (float a, float b)
{{
width = a; height = b;width = a; height = b;
}}
};};
class Rectangle: public Shapeclass Rectangle: public Shape
{{
public:public:
float area ()float area ()
{{
return (width * height);return (width * height);
}}
};};
class Triangle: public Shapeclass Triangle: public Shape
{{
public:public:
float area ()float area ()
{{
return (width * height) / 2;return (width * height) / 2;
}}
};};
int main ()int main ()
{{
Rectangle rect; Triangle tri;Rectangle rect; Triangle tri;
rect.set data (5,3);rect.set data (5,3);
tri.set data (2,5);tri.set data (2,5);
cout << rect.area() << endl;cout << rect.area() << endl;
cout << tri.area() << endl;cout << tri.area() << endl;
return 0;return 0;
}}
Output: 15Output: 15
55
Resolution in InheritanceResolution in Inheritance
class Aclass A
{{
public:public:
void display ()void display ()
{ cout << “Class A n“;}{ cout << “Class A n“;}
};};
class B : public Aclass B : public A
{{
public:public:
void display ()void display ()
{ cout << “Class B n“;}{ cout << “Class B n“;}
};};
void main( )void main( )
{{
B b;B b;
b.display( );b.display( ); // in B// in B
b.A::display( );b.A::display( ); // in A// in A
b.B::display( );b.B::display( ); // in B// in B
}}
continue …
Thank YouThank You

More Related Content

What's hot

Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
colleges
 
OOP C++
OOP C++OOP C++
OOP C++
Ahmed Farag
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Burhan Ahmed
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
Sanjit Shaw
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS
abhishek kumar
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vishal Patil
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
Friend Function
Friend FunctionFriend Function
Friend Function
Mehak Tawakley
 
Inheritance
InheritanceInheritance
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
Dr Sukhpal Singh Gill
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
Hirra Sultan
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4
MOHIT TOMAR
 
Oops concept on c#
Oops concept on c#Oops concept on c#
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
Inheritance in Object Oriented Programming
Inheritance in Object Oriented ProgrammingInheritance in Object Oriented Programming
Inheritance in Object Oriented Programming
Ashita Agrawal
 
Inheritance in c++theory
Inheritance in c++theoryInheritance in c++theory
Inheritance in c++theory
ProfSonaliGholveDoif
 
C++
C++C++

What's hot (20)

Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
OOP C++
OOP C++OOP C++
OOP C++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Friend Function
Friend FunctionFriend Function
Friend Function
 
Inheritance
InheritanceInheritance
Inheritance
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Inheritance in Object Oriented Programming
Inheritance in Object Oriented ProgrammingInheritance in Object Oriented Programming
Inheritance in Object Oriented Programming
 
Inheritance in c++theory
Inheritance in c++theoryInheritance in c++theory
Inheritance in c++theory
 
C++
C++C++
C++
 

Viewers also liked

4GMAT Diagnostic Test Q14 - Problem Solving - Coordinate Geometry
4GMAT Diagnostic Test Q14 - Problem Solving - Coordinate Geometry4GMAT Diagnostic Test Q14 - Problem Solving - Coordinate Geometry
4GMAT Diagnostic Test Q14 - Problem Solving - Coordinate Geometry
4gmatprep
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
shatha00
 
Inheritance
InheritanceInheritance
Inheritance
Anurag Daware
 
Oop inheritance
Oop inheritanceOop inheritance
Oop inheritance
Zubair CH
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
Hadziq Fabroyir
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
Ronak Chhajed
 
OOP Chapter 8 : Inheritance
OOP Chapter 8 : InheritanceOOP Chapter 8 : Inheritance
OOP Chapter 8 : Inheritance
Atit Patumvan
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
Shubham Vishwambhar
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
Hadziq Fabroyir
 
Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
Saharsh Anand
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
Anastasia Jakubow
 
Sreelekshmi power point presentation
Sreelekshmi power point presentationSreelekshmi power point presentation
Sreelekshmi power point presentation
softislandsolutions
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
Aabha Tiwari
 
Tutorial linear equations and linear inequalities
Tutorial linear equations and linear inequalitiesTutorial linear equations and linear inequalities
Tutorial linear equations and linear inequalities
khyps13
 
9 2 the area of a triangle
9 2 the area of a triangle9 2 the area of a triangle
9 2 the area of a triangle
hisema01
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
10.2 - Area of a Triangle
10.2 - Area of a Triangle10.2 - Area of a Triangle
10.2 - Area of a Triangle
mrwilliams
 
11.1 area of triangles and parallelograms
11.1 area of triangles and parallelograms11.1 area of triangles and parallelograms
11.1 area of triangles and parallelograms
Jessica Garcia
 
Machine Learning
Machine LearningMachine Learning
Machine Learning
Anastasia Jakubow
 

Viewers also liked (20)

4GMAT Diagnostic Test Q14 - Problem Solving - Coordinate Geometry
4GMAT Diagnostic Test Q14 - Problem Solving - Coordinate Geometry4GMAT Diagnostic Test Q14 - Problem Solving - Coordinate Geometry
4GMAT Diagnostic Test Q14 - Problem Solving - Coordinate Geometry
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Oop inheritance
Oop inheritanceOop inheritance
Oop inheritance
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
OOP Chapter 8 : Inheritance
OOP Chapter 8 : InheritanceOOP Chapter 8 : Inheritance
OOP Chapter 8 : Inheritance
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
 
Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
 
Sreelekshmi power point presentation
Sreelekshmi power point presentationSreelekshmi power point presentation
Sreelekshmi power point presentation
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
 
Tutorial linear equations and linear inequalities
Tutorial linear equations and linear inequalitiesTutorial linear equations and linear inequalities
Tutorial linear equations and linear inequalities
 
9 2 the area of a triangle
9 2 the area of a triangle9 2 the area of a triangle
9 2 the area of a triangle
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
10.2 - Area of a Triangle
10.2 - Area of a Triangle10.2 - Area of a Triangle
10.2 - Area of a Triangle
 
11.1 area of triangles and parallelograms
11.1 area of triangles and parallelograms11.1 area of triangles and parallelograms
11.1 area of triangles and parallelograms
 
Machine Learning
Machine LearningMachine Learning
Machine Learning
 

Similar to Inheritance OOP Concept in C++.

Inheritance
InheritanceInheritance
Inheritance
Aadhi Aadhithya
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
WaqarRaj1
 
Inheritance
InheritanceInheritance
Inheritance
Pranali Chaudhari
 
Inheritance
InheritanceInheritance
Inheritance
InheritanceInheritance
Inheritance
SangeethaSasi1
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
RAJ KUMAR
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
LadallaRajKumar
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
classall
 
Chapter25 inheritance-i
Chapter25 inheritance-iChapter25 inheritance-i
Chapter25 inheritance-i
Deepak Singh
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
Nilesh Dalvi
 
Inheritance, Object Oriented Programming
Inheritance, Object Oriented ProgrammingInheritance, Object Oriented Programming
Inheritance, Object Oriented Programming
Arslan Waseem
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
sushamaGavarskar1
 
Inheritance
InheritanceInheritance
Inheritance
prashant prath
 
Inheritance
InheritanceInheritance
Inheritance
poonam.rwalia
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Inheritance
InheritanceInheritance
Inheritance
piyush shukla
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
SudhanshuVijay3
 
Inheritance
InheritanceInheritance
Inheritance
Munsif Ullah
 
inheritance
inheritanceinheritance
inheritance
Amir_Mukhtar
 

Similar to Inheritance OOP Concept in C++. (20)

Inheritance
InheritanceInheritance
Inheritance
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
Chapter25 inheritance-i
Chapter25 inheritance-iChapter25 inheritance-i
Chapter25 inheritance-i
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
Inheritance, Object Oriented Programming
Inheritance, Object Oriented ProgrammingInheritance, Object Oriented Programming
Inheritance, Object Oriented Programming
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance
InheritanceInheritance
Inheritance
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Inheritance
InheritanceInheritance
Inheritance
 
inheritance
inheritanceinheritance
inheritance
 

Recently uploaded

Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 

Recently uploaded (20)

Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 

Inheritance OOP Concept in C++.

  • 3. IntroductionIntroduction  Reusability is an important feature ofReusability is an important feature of OOP.OOP.  C++ strongly supports the conceptC++ strongly supports the concept of reusability.of reusability.
  • 4. IntroductionIntroduction  The mechanism of deriving a newThe mechanism of deriving a new class from an old one is calledclass from an old one is called inheritance (or derivation).inheritance (or derivation).  The old class is referred to as baseThe old class is referred to as base class.( superclass, parent)class.( superclass, parent)  The new class is called the derivedThe new class is called the derived class or subclass.(child)class or subclass.(child) continue …
  • 5. IntroductionIntroduction  The derived class inherits some or allThe derived class inherits some or all of the attributes and functions fromof the attributes and functions from the base class.the base class.  A class can also inherit propertiesA class can also inherit properties from more than one class or fromfrom more than one class or from more than one level.more than one level. continue …
  • 6. Single InheritanceSingle Inheritance  A derived class with only one baseA derived class with only one base class.class. A B
  • 7. Multiple InheritanceMultiple Inheritance  A derived class with several baseA derived class with several base classes.classes. A C B
  • 8. Multilevel InheritanceMultilevel Inheritance  The mechanism of deriving a classThe mechanism of deriving a class from another derived class.from another derived class. A C B
  • 9. Derived ClassesDerived Classes  A derived class can be defined byA derived class can be defined by specifying its relationship with thespecifying its relationship with the base class in addition to its ownbase class in addition to its own details.details. classclass derived-class-namederived-class-name :: visibility-modevisibility-mode base-class-namebase-class-name {{ ………………//// ………………// members of derived class// members of derived class ………………//// };};
  • 10. Derived ClassesDerived Classes classclass derived-class-namederived-class-name :: visibility-modevisibility-mode base-class-namebase-class-name {{ ………………//// ………………// members of derived class// members of derived class ………………//// };}; The colon indicates that the derived-class-name is derived from the base-class-name The visibility mode is optional and , if present, may be either private or public. The default visibility mode is private. Visibility mode specifies whether the features of the base class are derived privately or publicly. continue …
  • 11. Derived ClassesDerived Classes  When a base class is privately derived by aWhen a base class is privately derived by a derived class, “public members” of the base classderived class, “public members” of the base class become “private members” of the derived class.become “private members” of the derived class.  Therefore the members of the derived class canTherefore the members of the derived class can only access the public members of the base class.only access the public members of the base class.  They are inaccessible to the objects of theThey are inaccessible to the objects of the derived class.derived class.  No member of the base class is accessible to theNo member of the base class is accessible to the objects of the derived class.objects of the derived class. continue …
  • 12. Derived ClassesDerived Classes  When a base class is publicly inherited,When a base class is publicly inherited, ”public members” of the base class”public members” of the base class become the “public members” of thebecome the “public members” of the derived class.derived class.  They are accessible to the objects of theThey are accessible to the objects of the derived class.derived class. continue …
  • 13. Derived ClassesDerived Classes  The private members of the base class areThe private members of the base class are not inherited in both the casesnot inherited in both the cases (publicly/privately inherited).(publicly/privately inherited).  The private members of a base class willThe private members of a base class will never become the members of its derivednever become the members of its derived class.class. continue …
  • 14. InheritanceInheritance  In inheritance, some of the base class dataIn inheritance, some of the base class data elements and member functions are inherited intoelements and member functions are inherited into the derived class.the derived class.  We can add our own data and member functionsWe can add our own data and member functions for extending the functionality of the base class.for extending the functionality of the base class.  It is a powerful tool for incremental programIt is a powerful tool for incremental program development.development.
  • 15. Effect of Inheritance on the visibility of MembersEffect of Inheritance on the visibility of Members Private Protected Public Private Protected Public Private Protected Private Protected Public Public Not inheritableNot inheritable Class B Class D1 : public B Class D2 : private B Class X : public D1, protected D2
  • 16. VisibilityVisibility Base classBase class visibilityvisibility Derived class visibilityDerived class visibility PublicPublic DerivationDerivation PrivatePrivate DerivationDerivation ProtectedProtected DerivationDerivation PrivatePrivate  NotNot InheritedInherited NotNot InheritedInherited NotNot InheritedInherited ProtectedProtected  ProtectedProtected PrivatePrivate ProtectedProtected PublicPublic  PublicPublic PrivatePrivate ProtectedProtected
  • 17. class Shapeclass Shape {{ protected:protected: float width, height;float width, height; public:public: void set data (float a, float b)void set data (float a, float b) {{ width = a; height = b;width = a; height = b; }} };}; class Rectangle: public Shapeclass Rectangle: public Shape {{ public:public: float area ()float area () {{ return (width * height);return (width * height); }} };}; class Triangle: public Shapeclass Triangle: public Shape {{ public:public: float area ()float area () {{ return (width * height) / 2;return (width * height) / 2; }} };}; int main ()int main () {{ Rectangle rect; Triangle tri;Rectangle rect; Triangle tri; rect.set data (5,3);rect.set data (5,3); tri.set data (2,5);tri.set data (2,5); cout << rect.area() << endl;cout << rect.area() << endl; cout << tri.area() << endl;cout << tri.area() << endl; return 0;return 0; }} Output: 15Output: 15 55
  • 18. Resolution in InheritanceResolution in Inheritance class Aclass A {{ public:public: void display ()void display () { cout << “Class A n“;}{ cout << “Class A n“;} };}; class B : public Aclass B : public A {{ public:public: void display ()void display () { cout << “Class B n“;}{ cout << “Class B n“;} };}; void main( )void main( ) {{ B b;B b; b.display( );b.display( ); // in B// in B b.A::display( );b.A::display( ); // in A// in A b.B::display( );b.B::display( ); // in B// in B }} continue …