
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Importance of @Override annotation in Java?
The @Override annotation is one of a default Java annotation and it can be introduced in Java 1.5 Version. The @Override annotation indicates that the child class method is over-writing its base class method.
The @Override annotation can be useful for two reasons
- It extracts a warning from the compiler if the annotated method doesn't actually override anything.
- It can improve the readability of the source code.
Syntax
public @interface Override
Example
class BaseClass { public void display() { System.out.println("In the base class,test() method"); } } class ChildClass extends BaseClass { @Override public void display() { System.out.println("In the child class, test() method"); } } // main class public class OverrideAnnotationTest { public static void main(String args[]) { System.out.println("@Override Example"); BaseClass test = new ChildClass(); test.display(); } }
Output
@Override Example In the child class, test() method
- Related Questions & Answers
- Importance of @JsonFilter annotation in Java?
- Importance of the Jackson @JsonInclude annotation in Java?
- Importance of @JsonRootName annotation using Jackson in Java?
- Importance of @JsonView annotation using Jackson in Java?
- Importance of @JsonIdentityInfo annotation using Jackson in Java?
- Importance of @JsonUnwrapped annotation using Jackson in Java?
- Importance of HashSet in Java
- Importance of StringReader class in Java?
- Importance of clone() method in Java?
- Importance of isDaemon() method in Java?
- Importance of XOR operator in Java?
- Importance of return type in Java?
- Importance of yield() method in Java?
- Importance of SerialVersionUID keyword in Java?
- Importance of join() method in Java?
Advertisements