Polymorphism

There are two types of polymorphisms
1. Compile time polymorphism (Method Overloading)
2.  Run time polymorphism (Method Overriding)
1. Compile time polymorphism 
It occurs during the method overloading.
The compiler decides which method to call this is called compile time polymorphism.

2.  Run time polymorphism
It occurs during the method overriding.
Method call is decided by JVM during runtime.
We already know method overloading clearly now let's discuss about runtime polymorphism.

Runtime Polymorphism
Rules :
1. The reference variable can points to its own class object.
2. Reference variable can points to its child class object it is called upcasting in Java.
3. Reference variable cannot points to its parent class object.

Post a Comment

0 Comments