Visit our Youtube channel to access new animated learning tricks Click Here.
0 votes
3.2k views
by (7.1k 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
by (7.1k 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

Related questions

0 votes
1 answer 2.2k views
0 votes
1 answer 63 views
0 votes
1 answer 2.6k views
Sharing improves retention
...