Home >Java >javaTutorial >What is the importance of @Override annotation in Java?
@Override annotation is one of the default Java annotations and can be introduced in Java 1.5 version. The @Override annotation indicates that the subclass method is overriding its base class method .
@Override Annotations work for two reasons
public @interface Override
class BaseClass { public void display() { System.out.println("In the base class,test() method"); } } class ChildClass extends BaseClass { <strong> </strong>@Override <strong> </strong> public void display() { System.out.println("In the child class, test() method"); } } // main class<strong> </strong>public class OverrideAnnotationTest { public static void main(String args[]) { System.out.println("@Override Example"); BaseClass test = new ChildClass(); test.display(); } }
@Override Example In the child class, test() method
The above is the detailed content of What is the importance of @Override annotation in Java?. For more information, please follow other related articles on the PHP Chinese website!