What exactly is the significance of 'override' | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What exactly is the significance of 'override'

7th Aug 2017, 5:33 PM
Kartik Vashisht
3 Answers
+ 4
Overriding replaces the implementation of the parent method. The parent method in this case being start() in the Machine class. So, with your code, you created a new implementation of the method for that object in the anonymous inner class. Had you of created a second object without using anonymous classes, the output would be: "Starting....". @Override is an Anotation to indicate that you are in fact Overriding something. If the method isn't Overriding something and you use the annotation, an exception will occur. For good programming standards, always use the annotation. To make things easier to read, I usually put the annotation on its own line. Ex/ @Override public void myMethod(){ }
7th Aug 2017, 6:40 PM
Rrestoring faith
Rrestoring faith - 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, 2:59 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
0
https://code.sololearn.com/cbSfl04QVfVA/?ref=app help me in this code answering my question
7th Aug 2017, 5:35 PM
Kartik Vashisht