We use the @Override
annotation as part of method declaration. The @Override
annotation is used when we want to override methods and want to make sure have overridden the correct methods.
As the annotation name we know that there should be the same method signature in the parent class to override. That means using this annotation let us know earlier when we are mistakenly override method that doesn’t exist in the base class.
package org.kodejava.basic;
public class OverrideExample {
private String field;
private String attribute;
@Override
public int hashCode() {
return field.hashCode() + attribute.hashCode();
}
@Override
public String toString() {
return field + " " + attribute;
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024