SlideShare a Scribd company logo
Inheritance
OpenLab[openlabword@gmail.com] 2
Define
● Deriving new classes from existing classes
such that the new classes acquire all the
features of existing classes is called
inheritance
OpenLab[openlabword@gmail.com] 3
How
● Use of keyword extends
A
B
<extends>
class A
{
- - -
- - -
- - -
}
class B extends A
{
- - -
- - -
- - -
}
Super Class
Sup Class
OpenLab[openlabword@gmail.com] 4
Types of Inheritance in Java
● Multilevel Inheritance
A
B
● Simple Inheritance
C
A
B C. . .
OpenLab[openlabword@gmail.com] 5
Why ????
● Why NO to multiple Inheritance in Java ?
Dimond Problem A
B C
D
OpenLab[openlabword@gmail.com] 6
Multiple Inheritance
A
B C
OpenLab[openlabword@gmail.com] 7
NOTE
“When SUB Class object is created , first of all
the super class default constructor is called and
then only SUB class constructor is called”
OpenLab[openlabword@gmail.com] 8
From SubClass To SuperClass
● Private Members not accessible from
SubClass
● From SubClass object we can access the
SuperClass methods and properties
● From SuperClass object we can not access
the SubClass methods and properties
OpenLab[openlabword@gmail.com] 9
A
B
B b new B( )=
Reference of Sub Class
Object of Sub Class
<extends>
SUB:SUB
<access>
<access>
OpenLab[openlabword@gmail.com] 10
A
B
A a new A( )=
Reference of SUPER Class
Object of SUPER Class
<extends>
SUPER:SUPER
<access>
OpenLab[openlabword@gmail.com] 11
Protected Specifier
● It is commonly used in SUPER class to make
the member of the SUPER class available
directly in its SUB class.
OpenLab[openlabword@gmail.com] 12
Overriding
● An instance method in a SUB class with the
same signature and return type as an
instance method in the SUPER class
overrides the superclass's method
OpenLab[openlabword@gmail.com] 13
SUB:SUB
[Method:Override]
A
B
B b new B( )=
Reference of Sub Class
Object of Sub Class
<extends>
<access>
<CAT>
<access>
<CAT>
OpenLab[openlabword@gmail.com] 14
Rules for Overriding
● Argument and return type must be same
● A final method can not be overridden
● A method declared static cannot be override
● If a method cannot be inherited , then it cannot
be override
● Constructors cannot be override
OpenLab[openlabword@gmail.com] 15
Run Time Polymorphism
● It is also called as dynamic polymorphism
A
B
C
A a
A a
A a
= new A( )
= new B( )
= new C( )
a.
i)
ii)
iii)
OpenLab[openlabword@gmail.com] 16
Overloading vs Overriding
● Overloading
– Static/Compile time
Polymorphism
– JVM decides which
method is called
depending on the
difference in the
method signature
– It is done in same class
– Method return type can
be same or different
● Overriding
– Dynamic/Run Time
Polymorphism
– JVM decides which
method is called
depending on the data
type of the object used to
calls
– It is done in SUPER and
SUB class
– Method return type
should also be same
OpenLab[openlabword@gmail.com] 17
super
● From SUB class object we can access the
super class methods and properties
● Use of super :-
– If we have same names of member in SUB as in
SUPER class then SUB members are accessible
– Invoke SUPER class constructor
OpenLab[openlabword@gmail.com] 18
final
● Final Methods
– Methods declared final are called final methods
– NO to overriding : As : NOT available to SUB
class
– When we wish that its implementation should not be
changed
● Final Class
– NO to SUB class : NO to inheritance
OpenLab[openlabword@gmail.com] 19
Type Casting
OpenLab[openlabword@gmail.com] 20
A
B
A a new B( )=
Reference of SUPER Class
Object of SUB Class
<extends>
Exclusive:Methods
[Widening/Generalization]
OpenLab[openlabword@gmail.com] 21
A
B
A a new B( )=
Reference of SUPER Class
Object of SUB Class
<extends>
Override:Methods
[Widening/Generalization]
OpenLab[openlabword@gmail.com] 22
A
B
B b new A( )=
Reference of Sup Class
Object of Super Class
<extends>
Exclusive:Methods
[Narrowing:Specialization]
OpenLab[openlabword@gmail.com] 23
A
B
A a
B b
new B( )
(B) a
=
Reference of SUPER Class
Object of Super Class
<extends>
Exclusive:Methods
[Narrowing:Specialization]
=
OpenLab[openlabword@gmail.com] 24
A
B
A a
B b
new B( )
(B) a
=
Reference of SUPER Class
Object of Super Class
<extends>
Override:Methods
[Narrowing:Specialization]
=
OpenLab[openlabword@gmail.com] 25
Type Casting
Referenced Data Type
ParentGeneralization
/Downcasting
Specialization
/Upcasting
* study in detail after inheritence

More Related Content

PPT
Process program9 cm604.5
PDF
Smalltalk on the JVM
PPTX
Advanced oops concept using asp
PPTX
Java principles
PDF
Building Complex Topology using NS3
PDF
NS3 Overview
PDF
1 session installation
PDF
Building Topology in NS3
Process program9 cm604.5
Smalltalk on the JVM
Advanced oops concept using asp
Java principles
Building Complex Topology using NS3
NS3 Overview
1 session installation
Building Topology in NS3

Viewers also liked (20)

PDF
Software Engineering Introduction
PDF
Fundamental of Shell Programming
PDF
Introduction of Cloud Computing
PDF
Socio-technical System
ODP
Introduction to Virtualization
PDF
Support formobility
PPT
PPT
PDF
Socket Programming using Java
PDF
Tutorial ns 3-tutorial-slides
PDF
Ns3 implementation wifi
PDF
ns-3 Tutorial
PDF
Mobile transportlayer
PPT
Quality planning
PDF
WLAN - IEEE 802.11
PDF
Network Simulation NS3
PDF
ns-3: History and Future
PPTX
COGNITIVE RADIO
PPTX
Cognitive radio networks
PPTX
Cognitive Radio, Introduction and Main Issues
Software Engineering Introduction
Fundamental of Shell Programming
Introduction of Cloud Computing
Socio-technical System
Introduction to Virtualization
Support formobility
Socket Programming using Java
Tutorial ns 3-tutorial-slides
Ns3 implementation wifi
ns-3 Tutorial
Mobile transportlayer
Quality planning
WLAN - IEEE 802.11
Network Simulation NS3
ns-3: History and Future
COGNITIVE RADIO
Cognitive radio networks
Cognitive Radio, Introduction and Main Issues
Ad

Similar to Inheritance (20)

PDF
‏‏‏‏‏‏oop lecture objectives will come.pdf
PPTX
Ch5 inheritance
PPTX
Modules 333333333³3444444444444444444.pptx
PPTX
PPTX
Unit3 part2-inheritance
PPTX
OBJECT ORIENTED PROGRAMMING_Unit2_NOTES.pptx
PPTX
Chap3 inheritance
PPT
Java inheritance
PPTX
OBJECT ORIENTED PROGRAMMING STRUCU2.pptx
PPTX
Unit3 inheritance
PPTX
Inheritance in java
PPTX
OBJECT ORIENTED PROGRAMMING_Unit2_firsthalf Updated.pptx
PPTX
Java Inheritance - sub class constructors - Method overriding
PDF
Java Inheritance
PPT
L7 inheritance
PPT
L7 inheritance
PPTX
Chapter 8.2
PPT
Ap Power Point Chpt7
PPTX
‏‏‏‏‏‏oop lecture objectives will come.pdf
Ch5 inheritance
Modules 333333333³3444444444444444444.pptx
Unit3 part2-inheritance
OBJECT ORIENTED PROGRAMMING_Unit2_NOTES.pptx
Chap3 inheritance
Java inheritance
OBJECT ORIENTED PROGRAMMING STRUCU2.pptx
Unit3 inheritance
Inheritance in java
OBJECT ORIENTED PROGRAMMING_Unit2_firsthalf Updated.pptx
Java Inheritance - sub class constructors - Method overriding
Java Inheritance
L7 inheritance
L7 inheritance
Chapter 8.2
Ap Power Point Chpt7
Ad

Recently uploaded (20)

PPTX
Lecture Notes Electrical Wiring System Components
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
web development for engineering and engineering
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Sustainable Sites - Green Building Construction
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Well-logging-methods_new................
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
OOP with Java - Java Introduction (Basics)
DOCX
573137875-Attendance-Management-System-original
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
PPT on Performance Review to get promotions
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Lecture Notes Electrical Wiring System Components
Operating System & Kernel Study Guide-1 - converted.pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
web development for engineering and engineering
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Sustainable Sites - Green Building Construction
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Well-logging-methods_new................
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Lesson 3_Tessellation.pptx finite Mathematics
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
OOP with Java - Java Introduction (Basics)
573137875-Attendance-Management-System-original
Foundation to blockchain - A guide to Blockchain Tech
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPT on Performance Review to get promotions
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd

Inheritance