![]() |
VOOZH | about |
The @Override annotation is a predefined annotation in Java that indicates a method in a subclass is intended to override a method from its superclass or an implemented interface. It was introduced in Java 5 and helps the compiler verify that method overriding is performed correctly.
Syntax:
@Override
returnType methodName(parameters) {
// method body
}
Example: Java Program Illustrating Override Annotation without using abstract class
Example of @Override annotation We are in child class method
Explanation: The ChildClass inherits from ParentClass and overrides the display() method. When obj.display() is called using a parent reference, the overridden method in ChildClass executes, demonstrating method overriding and runtime polymorphism.
Example: Java Program Illustrating Override Annotation with using abstract class
This is Car This is Bike
Explanation: The abstract class Vehicle declares the abstract method method(). The Car and Bike classes override this method and provide their own implementations. When the method is called, the respective class-specific implementation is executed.
@Override Annotation