SlideShare a Scribd company logo
NAME: R.PRASHANTHAN
CLASS: 1ST YEAR B.Ed. ‘B’
ROLL.NO: 54
SUBJECT: COMPUTER SCIENCE
TOPIC: INHERITANCE
INHERITANCE
 The mechanism
of deriving a new
class from an old
one is called
Inheritance.
 The new class is
a specialized
version of the
existing class
C++ and inheritance
Base Class (or superclass): the class being
inherited from
Derived Class (or subclass): the class that
inherits
The "is a" Relationship
 Inheritance establishes an "is a" relationship
between classes.
 A poodle is a dog
 A car is a vehicle
 A flower is a plant
 A football player is an athlete
Need for Inheritance
Capability of inheriting features.
Transitive relationship.
Reusability of class.
Advantages of inheritance
When a class inherits from another class, there are
three benefits:
(1) You can reuse the methods and data of the
existing class.
(2) You can extend the existing class by adding
new data and new methods.
(3) You can modify the existing class by
overloading its methods with your own
implementations.
Benefits of Inheritance
 Code is reused
grad_student uses tested code from student
 Reflects relationship in problem domain
Special grouping grad_ student outgrowth of real
world and treatment of this group
 Polymorphic mechanisms allow client code to treat
inherited class as subtype of base class
Simplifies code, maintains subtype distinctions ##
Raj
Father
Rani Roshan
Base Class
Derived Class
Existing
class is
called Base
Class.
New class is called
derived class.
INHERITANCE
SINGLE INHERITANCE
MULTIPLE INHERITANCE
MULTILEVEL
INHERITANCE
HIERARCHICAL
INHERITANCE
HYBRID INHERITANCE
When a subclass inherit only from one base class,it is known as
single inheritance.
Super Class
Derived Class
Super Class
(Base Class)
Sub Class
(Derived Class)
Syntax:
Class Derived-class : Mode base-class
{
St1;
St2;
};
Colon gives that derived class-name is
derived from base-class.
Mode is either private or public.By
default mode is private
Base Class & Derived Class
The new class is called Derived Class and old one is called Base class.
Class Student
{
Public: int Roll;
};
Class Ipstudent : public Student
{
Private : int ipmarks;
Public : void info( )
{ cout<< Roll;
cout<<ipmarks;
}
};
Main( )
{ ipstudent ip;
ip.Roll=1;
Ip.info( );
}
When many subclasses inherit from a single base class ,it
is known as hierarchical inheritance.
Syntax:
Class Base-class : Mode Derived-class 1,Mode Derived-class 2
{
St1;
St2;
};
Mode is either private or public.By
default mode is private
Name of different Derived-class
Super Class
Sub Class 2
Sub Class 1
When a subclass inherits from a class that itself
inherits from another class it is known as
multilevel inheritance.
When one subclass inheriting from many base class ,it is
known as hierarchical inheritance. Syntax:
Syntax:
Class Derived-class : Mode base-class1,Mode base-class2
{
St1;
St2;
};
Mode is either private or public.By
default mode is private
Name of different base class
When a subclass inherits from multiple base classes and all of its base
classes inherit from a single base class,this form of inheritance is
known as hybrid inheritance..
Virtual Inheritance
The derived class AutoBoat…
Inherits Attributes and Properties
From
Automobile
MotorBoat
Vehicle
Public, Private, and Protected Inheritance
Visibility Mode
 Private When base class is privately accessed by
derived class then
 Public member Private
 Protected member Private
 Private member Not inherited
Base Class Derived Class
become
Visibility Mode
 Public When base class is publicly accessed by
derived class then
• Private member Not inherited
• Public member Public
• Protected member Protected
Base Class Derived Class
Visibility Mode
 Protected When base class is accessed protectly
by derived class then
 Private member Not inherited
 Public member Public
 Protected member Protected
Base Class Derived Class
The significance of visibility modes
Private :-When the derived class require to use
some attributes of the base class and these inherited
features are intended not to be inherited further .
Public :-When the situation wants the derived class
to have all the attributes of the base class,plus some
extra attributes.
Protected:- When the features are required to be
hidden from the outside world and at same time
required to be inheritable.
Accessibility of base class member
Access
Specifier
Accessible
from own class
Accessible from
derived
class(inheritable)
Accessible from
object outside
class
Public Yes Yes Yes
Protected Yes Yes No
Private Yes No No
Inheritance

More Related Content

What's hot (18)

Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Oop inheritance
Oop inheritanceOop inheritance
Oop inheritance
 
Object Oriented Programming - 7.1. Inheritance
Object Oriented Programming - 7.1. InheritanceObject Oriented Programming - 7.1. Inheritance
Object Oriented Programming - 7.1. Inheritance
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
 
C# Access modifiers
C# Access modifiersC# Access modifiers
C# Access modifiers
 
inheritance in C++
inheritance in C++inheritance in C++
inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Final presentation programming
Final presentation programmingFinal presentation programming
Final presentation programming
 
Java - Inheritance Concepts
Java - Inheritance ConceptsJava - Inheritance Concepts
Java - Inheritance Concepts
 
Inheritance in c++ by Manan Pasricha
Inheritance in c++ by Manan PasrichaInheritance in c++ by Manan Pasricha
Inheritance in c++ by Manan Pasricha
 
Inheritance
InheritanceInheritance
Inheritance
 

Similar to Inheritance

Similar to Inheritance (20)

lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Mca 2nd sem u-3 inheritance
Mca 2nd  sem u-3 inheritanceMca 2nd  sem u-3 inheritance
Mca 2nd sem u-3 inheritance
 
Inheritance
Inheritance Inheritance
Inheritance
 
Bca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritanceBca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritance
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
Inheritance
InheritanceInheritance
Inheritance
 
inheritance
   inheritance   inheritance
inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
week14 (1).ppt
week14 (1).pptweek14 (1).ppt
week14 (1).ppt
 
INHERITANCE
INHERITANCEINHERITANCE
INHERITANCE
 
session 24_Inheritance.ppt
session 24_Inheritance.pptsession 24_Inheritance.ppt
session 24_Inheritance.ppt
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
 
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
 
Lec5.ppt
Lec5.pptLec5.ppt
Lec5.ppt
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismDeeptiGupta154
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsCol Mukteshwar Prasad
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...Jisc
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptxJosvitaDsouza2
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxRaedMohamed3
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdfCarlosHernanMontoyab2
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfTamralipta Mahavidyalaya
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersPedroFerreira53928
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXMIRIAMSALINAS13
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

Inheritance

  • 1. NAME: R.PRASHANTHAN CLASS: 1ST YEAR B.Ed. ‘B’ ROLL.NO: 54 SUBJECT: COMPUTER SCIENCE TOPIC: INHERITANCE
  • 2. INHERITANCE  The mechanism of deriving a new class from an old one is called Inheritance.  The new class is a specialized version of the existing class
  • 3. C++ and inheritance Base Class (or superclass): the class being inherited from Derived Class (or subclass): the class that inherits
  • 4. The "is a" Relationship  Inheritance establishes an "is a" relationship between classes.  A poodle is a dog  A car is a vehicle  A flower is a plant  A football player is an athlete
  • 5. Need for Inheritance Capability of inheriting features. Transitive relationship. Reusability of class.
  • 6. Advantages of inheritance When a class inherits from another class, there are three benefits: (1) You can reuse the methods and data of the existing class. (2) You can extend the existing class by adding new data and new methods. (3) You can modify the existing class by overloading its methods with your own implementations.
  • 7. Benefits of Inheritance  Code is reused grad_student uses tested code from student  Reflects relationship in problem domain Special grouping grad_ student outgrowth of real world and treatment of this group  Polymorphic mechanisms allow client code to treat inherited class as subtype of base class Simplifies code, maintains subtype distinctions ##
  • 8. Raj Father Rani Roshan Base Class Derived Class Existing class is called Base Class. New class is called derived class.
  • 10. When a subclass inherit only from one base class,it is known as single inheritance. Super Class Derived Class Super Class (Base Class) Sub Class (Derived Class)
  • 11. Syntax: Class Derived-class : Mode base-class { St1; St2; }; Colon gives that derived class-name is derived from base-class. Mode is either private or public.By default mode is private
  • 12. Base Class & Derived Class The new class is called Derived Class and old one is called Base class. Class Student { Public: int Roll; }; Class Ipstudent : public Student { Private : int ipmarks; Public : void info( ) { cout<< Roll; cout<<ipmarks; } }; Main( ) { ipstudent ip; ip.Roll=1; Ip.info( ); }
  • 13. When many subclasses inherit from a single base class ,it is known as hierarchical inheritance.
  • 14. Syntax: Class Base-class : Mode Derived-class 1,Mode Derived-class 2 { St1; St2; }; Mode is either private or public.By default mode is private Name of different Derived-class
  • 15. Super Class Sub Class 2 Sub Class 1 When a subclass inherits from a class that itself inherits from another class it is known as multilevel inheritance.
  • 16. When one subclass inheriting from many base class ,it is known as hierarchical inheritance. Syntax:
  • 17. Syntax: Class Derived-class : Mode base-class1,Mode base-class2 { St1; St2; }; Mode is either private or public.By default mode is private Name of different base class
  • 18. When a subclass inherits from multiple base classes and all of its base classes inherit from a single base class,this form of inheritance is known as hybrid inheritance..
  • 19. Virtual Inheritance The derived class AutoBoat… Inherits Attributes and Properties From Automobile MotorBoat Vehicle
  • 20. Public, Private, and Protected Inheritance
  • 21. Visibility Mode  Private When base class is privately accessed by derived class then  Public member Private  Protected member Private  Private member Not inherited Base Class Derived Class become
  • 22. Visibility Mode  Public When base class is publicly accessed by derived class then • Private member Not inherited • Public member Public • Protected member Protected Base Class Derived Class
  • 23. Visibility Mode  Protected When base class is accessed protectly by derived class then  Private member Not inherited  Public member Public  Protected member Protected Base Class Derived Class
  • 24. The significance of visibility modes Private :-When the derived class require to use some attributes of the base class and these inherited features are intended not to be inherited further . Public :-When the situation wants the derived class to have all the attributes of the base class,plus some extra attributes. Protected:- When the features are required to be hidden from the outside world and at same time required to be inheritable.
  • 25. Accessibility of base class member Access Specifier Accessible from own class Accessible from derived class(inheritable) Accessible from object outside class Public Yes Yes Yes Protected Yes Yes No Private Yes No No