Java enables you to annotate methods that are intended to override a method in a superclass. Compilers are required to generate an error if such an annotated method does not override a method in a superclass, which provides increased protection from potential defects. An annotated method also improves code readability.

Add an @Override annotation to a method that is intended to override a method in a superclass.

In the following example, Triangle.getArea overrides Rectangle.getArea, so it is annotated with @Override.

  • J. Bloch, Effective Java (second edition), Item 36. Addison-Wesley, 2008.
  • Help - Eclipse Platform: Java Compiler Errors/Warnings Preferences.
  • Java API Specification: Annotation Type Override.
  • The Java Tutorials: Predefined Annotation Types.