The @Override annotation is used to indicate that a method is intended to override a method from a superclass or implement a method from an interface. Although it is optional, it helps the compiler verify the correctness of the overriding method and prevents common programming mistakes.
Suppose a child class wants to override a method from its parent class. The @Override annotation ensures that the method signature matches the parent method exactly.
class Animal {
void makeSound() {
System.out.println("Animal Sound");
}
}
class Dog extends Animal {
@Override
void makeSound() {
System.out.println("Dog Barks");
}
}
public class Demo {
public static void main(String[] args) {
Animal animal = new Dog();
animal.makeSound();
}
}Dog Barks
class Parent {
void display() {
}
}
class Child extends Parent {
@Override
void display() {
}
}The compiler confirms that display() correctly overrides the parent method.
class Parent {
void display() {
}
}
class Child extends Parent {
@Override
void disply() {
}
}method does not override or implement a method from a supertype
The annotation immediately catches the spelling mistake.
A concise interview answer is
@Override is an annotation that tells the compiler a method is intended to override a superclass method or implement an interface method. It helps detect errors such as incorrect method names or parameter lists and improves code readability and reliability.
Last updated: 16 July 2026
Previous question: What is method overriding in Java?
Next question: What happens if a superclass method is overridden by more than one subclass in Java?