The Difference Between Method Overloading & Overriding in Java!


Overloading is the implementation of two more methods in the same class with different parameters (or arguments).

Overriding is the implementation of two methods that have the same implementation but process differently.

For example, you want to run a pizza deal, you would make an override method for your order. If a person orders 1 pizza you would charge them one price. If they order two they may get 10% off.

However, if you want to override this “getPrice method”, you could override this.

By making a “subclass” extend the Super class (pizza) then we can override a method and return what we like. In this case, we have OVERRIDDEN the getPrice and made it return 5.

I hope this explains it simply for you!

Until next time Josh


Related:  What Are Labelled Transition Systems & How Are They Used?