Question:
Whats does @Override mean?
Answer:
The override annotation (@Override) indicates that a method declaration intends on overriding a method declaration in the classes supertype.
When overriding a method, you might want to use the @Override annotation that instructs the compiler that you intend to override a method in the superclass. If, for some reason, the compiler detects that the method does not exist in one of the superclasses, then it will generate an error.
When overriding a method, you might want to use the @Override annotation that instructs the compiler that you intend to override a method in the superclass. If, for some reason, the compiler detects that the method does not exist in one of the superclasses, then it will generate an error.
Code:
public class Animal { public void speak(){ } } class Cat extends Animal{ @Override public void speak(){ System.out.println("meow"); } }