What is method overriding in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

What is method overriding in java?

8th Mar 2017, 8:48 AM
‎‏‎‏‎Joe - avatar
3 Answers
+ 12
Added a little example for you at the playground: https://code.sololearn.com/c5pdVuw8Nmpe/?ref=app Hope it helps...
8th Mar 2017, 9:28 AM
Tashi N
Tashi N - avatar
+ 10
A method that is defined differently in a derived class than in the super class, but has the same declaration (but adding @Override annotation to method of the derived class). Simplest example: toString method. Try to print an object, when toString is not overridden. It will print the default toString of object (class name @ hashcode). If you override toString in your class, you can choose how it's gonna be printed. Any String return value is possible. During runtime it will be checked, if you overrode the method and use the overridden one if you call toString.
8th Mar 2017, 9:00 AM
Tashi N
Tashi N - avatar
+ 1
here is an example that you may want to check to see difference or understand the meanings of overriding and overloading https://code.sololearn.com/c0awDMpDLukF/?ref=app
11th Sep 2017, 3:00 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar