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
276 views
asked Dec 3, 2015 by nanospeck (3,940 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 (3,940 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

Do you have Mnemonics?

Submit your Mnemonics to Win Cash Prizes!


*Deadline: 15th March 2017
...