Good News Students! Become a Spellogram Contributor and Earn Money.Click Here To Know More!

How to remember the difference between Runtime polymorphism and Compile time polymorphism in Java?

0 votes
281 views
asked Dec 3, 2015 by nanospeck (4,590 points)

Often we might get confused by the following

Compiletime polymorphism class overloading in java
Runtime polymorphism class overriding in java

Both class overriding/overloading might get mixed up and can cause confusion.
What is an easy hack to remember this?

1 Answer

0 votes
answered Dec 3, 2015 by nanospeck (4,590 points)

The hack is to create a trick to remember only 'Runtime Polymorphism'. 
Here is simple piece of code about 'Bikes' relating to runtime polymorphism

class Bike {
public ride(){}
}

class HarleyDavidson extends Bike {
// Look!!! class-overriding below
public ride(){
System.out.println("Enable 6th gear");
}

}

Now here comes the trick.Runtime polymorphism can be imagined as something that always moves. Eg. our bike is a perfect example. You can ride it around. It's dynamic and it moves. 
So here 'ride' is the keyword.

Relate class-overriding with the method 'ride

The 'ride' method in the above example is an instance of class-overriding hence its very easy to remember now that Runtime Polymorpism is related with class-overriding

Get ₹100 per Contribution

Submit your Mnemonics to Earn Money Instantly!


*Deadline: 15th August 2017
...