+ 1
How its output is starting...
class Machine { public void start() { System.out.println("Starting..."); } } public static void main(String[ ] args) { Machine m1 = new Machine() { @Override public void start() { System.out.println("Wooooo"); } }; Machine m2 = new Machine(); m2.start(); }
2 Réponses
+ 7
Yes you're right Faisal
The override property is used to override members of parent class.
It's like re-writing them for child class.
I prepared a example for you Abhishek
https://code.sololearn.com/cYh0lW55Hs6a/?ref=app
+ 4
I may definitely be wrong in this, but from what it seems because you are only overriding the start function in m1, start() in m2 is unaffected and continues to use the default code for the class.