Answer the question
In order to leave comments, you need to log in
Why and where exactly to write @Override?
From the definition from the Internet, you can read what @Override means
In fact, the @Override annotation indicates that next we are going to override the base class method.
The annotation serves only to control the success of the action when building the project.
Answer the question
In order to leave comments, you need to log in
This annotation is written on methods that are overridden from the super class.
This is something like insurance, guaranteeing that a method is 100% overridden.
class A {
public void superMethod() {}
}
class B extends A {
@Override
public void superMethod() {}
}
It is desirable to write on all overridden methods, firstly, so that the person reading the code sees that this is an overridden method, and secondly, so that the compiler and IDE check its signature (parameters, access modifiers, return value) and prevent it from compiling if available errors, because if the signature is incorrect, then the method will not be called.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question