SlideShare a Scribd company logo
1 of 26
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

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

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