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

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
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
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
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
 
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
 

Recently uploaded (20)

Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
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
 
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 ...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
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
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
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
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
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
 
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
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
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...
 
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
 
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
 

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