+ 3

What does the keyword-- @Override means ,only for enhancing the code readability?

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("Woohoo....");} }; Machine m2=new Machine(); m2.start(); }

6th Feb 2022, 5:21 PM
Tripti Tiwari
Tripti Tiwari - avatar
1 Answer
+ 3
No, it does more than just add a readability annotation. It will throw an error during compilation if the following method does not match a signature to override. Where without the annotation a new method would be created, this will ensure that it is correctly overriding a method so that the intended action occurs.
6th Feb 2022, 5:47 PM
ChaoticDawg
ChaoticDawg - avatar