Why do we need method overriding?

Firstly let me explain what is overriding. Overriding means to give new implementation to a particular piece of code.

Suppose we have a piece of code that says that “My car has 800CC engine”. I start using this application, i say that no my car doesn’t have 800CC engine instead of that my car has 1200CC engine. This is my implementation for that particular piece of code

We use overriding when we have to change the functionality of particular method that was written by some other developer. But remember this will not change the code of the developer whose method you are overriding.

Whosoever use that developer code will be able to use developer’s method implementation. And whosoever use your class where you have overriden the method, will be able to access your implementation .

Example :

Be the first to comment

Leave a Reply

Your email address will not be published.