Lecture 4 - Polymorphism 3
Lecture 4 - Polymorphism 3
PROGRAMMING (JAVA)
LECTURE 4 – POLYMORPHISM
AND INTERFACES
Askar Khaimuldin
Senior-lecturer
[email protected]
z
Astana IT University
CONTENT
Concept of polymorphism
Overriding methods
Polymorphic Behaviour
Type Casting (narrowing conversion)
Abstract class
Interfaces
final methods and classes
CONCEPT OF
POLYMORPHISM
Polymorphism means “many forms”
“Program in the general” rather than “program in the
specific.”
Polymorphism enables you to write programs that
process objects that share the same superclass, either
directly/indirectly, as if they were all objects of the
superclass
Two basic types:
Compile time Polymorphism - Overloading
Runtime Polymorphism - Overriding
OVERRIDING METHODS
Method overriding it is a case of the runtime
polymorphism
JVM determines an appropriate method to be called at
the runtime
It is also called dynamic or late binding (Dynamic Method
Dispatch)
Method overriding says child class has the same method
as declared in the parent class
It means if child class provides the specific
implementation of the method that has been provided by
one of its parent class, then it is known as method
overriding
POLYMORPHIC BEHAVIOUR