Polymorphism in Java
Polymorphism in Java
What is Polymorphism?
Examples of Polymorphism
Types of Polymorphism
Essential conditions for achieving Polymorphism
Static Polymorphism
Q&A based on Static Polymorphism
Dynamic Polymorphism
Q&A based on Dynamic Polymorphism
Static v/s Dynamic Polymorphism
What is Polymorphism?
Method overloading: Method overloading is a feature that allows a class to include two or more
methods to have the same name but different parameter list.
Sample program for Static Polymorphism
Program
Output
Questions:
1. Can we achieve method overloading by changing the return type of method only?
It is also known as Run time Polymorphism. It is a process in which a function call to the
overridden method is resolved at Runtime. This type of polymorphism is achieved by
Method Overriding.
Method Overriding: Overriding is a feature that allows a subclass or child class to provide a
specific implementation of a method that is already provided by one of its super-classes or parent
classes.
Sample Program for Dynamic Polymorphism
Program:
Output:
Questions:
source: slideshare
THANK YOU