SlideShare a Scribd company logo
1 of 11
Download to read offline
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)

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
ย 
Soild principles
Soild principlesSoild principles
Soild principles
ย 

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
ย 
Plasma TFT
Plasma TFTPlasma TFT
Plasma TFT
ย 
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
ย 

Recently uploaded

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
ย 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
ย 
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
ย 
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
dharasingh5698
ย 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
ย 

Recently uploaded (20)

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ย 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
ย 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
ย 
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...
ย 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
ย 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
ย 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
ย 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
ย 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
ย 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
ย 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
ย 
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 ...
ย 
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
ย 
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
ย 
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
ย 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ย 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
ย 

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