SlideShare a Scribd company logo
1 of 11
Inheritance
Definition
In object-oriented programming, inheritance
enables new objects to take on the properties of
existing objects. A class that is used as the basis
for inheritance is called a superclass or base
class
Inheritance is a good choice when
โ— Your inheritance hierarchy represents an "is-a"
relationship and not a "has-a" relationship.
โ— You can reuse code from the base classes.
โ— You need to apply the same class and methods to
different data types.
โ— The class hierarchy is reasonably shallow, and other
developers are not likely to add many more levels.
โ— You want to make global changes to derived classes
by changing a base class.
Types
โ— The different types of inheritance are:
-Single Inheritance:
-Hierarchical Inheritance
Multiple inheritance
Multilevel Inheritance
Hybrid Inheritance
Advantages
โ— Reusability -- facility to use public methods of base
class without rewriting the same
โ— Extensibility -- extending the base class logic as per
business logic of the derived class
โ— Data hiding -- base class can decide to keep some data
private so that it cannot be altered by the derived class
โ— Overriding--With inheritance, we will be able to override
the methods of the base class so that meaningful
implementation of the base class method can be
designed in the derived class.
Disadvantages
โ— Main disadvantage of using inheritance is that the two classes (base
and inherited class) get tightly coupled.
โ— This means one cannot be used independent of each other.
โ— Also with time, during maintenance adding new features both base as
well as derived classes are required to be changed. If a method
signature is changed then we will be affected in both cases (inheritance
& composition)
โ— If a method is deleted in the "super class" or aggregate, then we will
have to re-factor in case of using that method
THANK YOU!

More Related Content

Similar to Inheritance

8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_feb
Raj Shah
ย 

Similar to Inheritance (20)

java_vyshali.pdf
java_vyshali.pdfjava_vyshali.pdf
java_vyshali.pdf
ย 
Introduction to Java -unit-1
Introduction to Java -unit-1Introduction to Java -unit-1
Introduction to Java -unit-1
ย 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
ย 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
ย 
Object oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented conceptsObject oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented concepts
ย 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
ย 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
ย 
Template pattern
Template patternTemplate pattern
Template pattern
ย 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
ย 
Salesforce Meetup Grasp and Solid in Apex (Speakers: Alexander Popok and Kons...
Salesforce Meetup Grasp and Solid in Apex (Speakers: Alexander Popok and Kons...Salesforce Meetup Grasp and Solid in Apex (Speakers: Alexander Popok and Kons...
Salesforce Meetup Grasp and Solid in Apex (Speakers: Alexander Popok and Kons...
ย 
Unit 3
Unit 3Unit 3
Unit 3
ย 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
ย 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
ย 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
ย 
Week5 inhertiance
Week5 inhertianceWeek5 inhertiance
Week5 inhertiance
ย 
Object Oriented Best Practices - Summary
Object Oriented Best Practices - SummaryObject Oriented Best Practices - Summary
Object Oriented Best Practices - Summary
ย 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_feb
ย 
Inheritance,constructor,friend function
Inheritance,constructor,friend functionInheritance,constructor,friend function
Inheritance,constructor,friend function
ย 
C# interview quesions
C# interview quesionsC# interview quesions
C# interview quesions
ย 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
ย 

More from Pradhan Rishi Sharma

More from Pradhan Rishi Sharma (20)

JAVA Threads explained
JAVA Threads explained JAVA Threads explained
JAVA Threads explained
ย 
JAVA Collection and generics
JAVA Collection and genericsJAVA Collection and generics
JAVA Collection and generics
ย 
Inheritance
InheritanceInheritance
Inheritance
ย 
0/1Knapsack
0/1Knapsack0/1Knapsack
0/1Knapsack
ย 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architecture
ย 
Aids Awareness , Nss , Healthcare !
Aids Awareness , Nss , Healthcare !Aids Awareness , Nss , Healthcare !
Aids Awareness , Nss , Healthcare !
ย 
D Flip Flop
D Flip Flop D Flip Flop
D Flip Flop
ย 
Optical fiber
Optical fiberOptical fiber
Optical fiber
ย 
Optical Fiber
Optical Fiber Optical Fiber
Optical Fiber
ย 
Algorithms
AlgorithmsAlgorithms
Algorithms
ย 
Algorithms
AlgorithmsAlgorithms
Algorithms
ย 
Algorithms
AlgorithmsAlgorithms
Algorithms
ย 
Algorithms
AlgorithmsAlgorithms
Algorithms
ย 
Lasers
Lasers Lasers
Lasers
ย 
Solar Energy
Solar Energy Solar Energy
Solar Energy
ย 
Solar Energy
Solar EnergySolar Energy
Solar Energy
ย 
Solar Energy
Solar Energy Solar Energy
Solar Energy
ย 
Beam , support and reaction
Beam , support and reaction Beam , support and reaction
Beam , support and reaction
ย 
Beam , support and reaction
Beam , support and reaction Beam , support and reaction
Beam , support and reaction
ย 
Cement
CementCement
Cement
ย 

Recently uploaded

VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
SUHANI PANDEY
ย 
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort ServiceCall Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
ย 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
ย 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
ย 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
sivaprakash250
ย 

Recently uploaded (20)

University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
ย 
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort ServiceCall Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
ย 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ย 
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
ย 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
ย 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
ย 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
ย 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
ย 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
ย 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
ย 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ย 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
ย 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
ย 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
ย 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
ย 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
ย 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
ย 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
ย 

Inheritance

  • 2. Definition In object-oriented programming, inheritance enables new objects to take on the properties of existing objects. A class that is used as the basis for inheritance is called a superclass or base class
  • 3. Inheritance is a good choice when โ— Your inheritance hierarchy represents an "is-a" relationship and not a "has-a" relationship. โ— You can reuse code from the base classes. โ— You need to apply the same class and methods to different data types. โ— The class hierarchy is reasonably shallow, and other developers are not likely to add many more levels. โ— You want to make global changes to derived classes by changing a base class.
  • 4. Types โ— The different types of inheritance are: -Single Inheritance:
  • 9. Advantages โ— Reusability -- facility to use public methods of base class without rewriting the same โ— Extensibility -- extending the base class logic as per business logic of the derived class โ— Data hiding -- base class can decide to keep some data private so that it cannot be altered by the derived class โ— Overriding--With inheritance, we will be able to override the methods of the base class so that meaningful implementation of the base class method can be designed in the derived class.
  • 10. Disadvantages โ— Main disadvantage of using inheritance is that the two classes (base and inherited class) get tightly coupled. โ— This means one cannot be used independent of each other. โ— Also with time, during maintenance adding new features both base as well as derived classes are required to be changed. If a method signature is changed then we will be affected in both cases (inheritance & composition) โ— If a method is deleted in the "super class" or aggregate, then we will have to re-factor in case of using that method