Recommended Free Tools
In Java, method overriding lets a subclass provide its own implementation of an inherited instance method. When that method is called through a superclass or interface reference, Java selects the implementation for the object’s runtime class. Use @Override so the compiler can confirm that you really are overriding a method.
How method overriding works
An override requires an inherited instance method and a compatible instance method declaration in a subclass or implementing class. The reference type determines which methods are available at compile time; for an overridable instance-method call, the runtime object determines which implementation runs.
class Animal {
String sound() { return "?"; }
}
class Dog extends Animal {
@Override
String sound() { return "woof"; }
}
Animal pet = new Dog();
System.out.println(pet.sound()); // woof
Although pet is declared as Animal, it refers to a Dog object, so the call runs Dog.sound(). This runtime selection is polymorphism. Oracle’s polymorphism tutorial demonstrates the same principle; Oracle notes that its tutorials were written for JDK 8, so use the Java SE 25 Language Specification for current language rules.
Why use @Override?
The annotation tells readers that the declaration is intended to override an inherited method, and asks the compiler to verify that relationship. If a name or parameter list is mistyped, compilation fails rather than quietly creating an unrelated overload. Consistently annotate overrides; see Oracle’s overriding and hiding tutorial.
Overriding, overloading, and static hiding
| Concept | What changes | How Java selects the method |
|---|---|---|
| Overriding | A subclass provides a compatible implementation of an inherited instance method. | For an instance call, the runtime object’s class determines the implementation. |
| Overloading | A method has the same name but a different parameter list. A subclass may overload an inherited method. | The compiler resolves which overload applies from the call’s available types and arguments. |
| Static hiding | A subclass declares a same-signature static method. | The qualifying type at compile time determines the method; this is not runtime polymorphism. |
A static method does not override an instance method, and an instance method does not override a static method. For static methods, use the class name to make the qualifying type explicit rather than calling the method through an object reference.
Rules an overriding method must satisfy
Java checks more than whether the method names match. The overriding declaration must have a subsignature compatible with the inherited method, and it must satisfy the inherited method’s contract.
Rank #2
- Return type: A reference return type may be covariant: an override can return a subtype, such as
Dogwhen the inherited method returnsAnimal. Primitive return types must match. - Access: An override cannot make the method less accessible. A
publicmethod must remain public; aprotectedmethod may remain protected or become public; package access cannot become private. - Checked exceptions: An override cannot add checked exceptions beyond what the inherited declaration allows.
- Final methods: A method declared
finalcannot be overridden. - Inheritance and visibility: Confirm that the superclass declaration is inherited and visible to the subclass; private methods are not inherited as overridable methods.
These constraints are specified in Chapter 8 of the Java SE 25 Language Specification.
Methods that cannot be overridden
Private methods
A private superclass method is not inherited as an overridable method. A subclass may declare a method with the same name and parameters, but that declaration is separate; it does not replace the private method.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallFinal methods and classes
A final method cannot be overridden. A final class cannot be subclassed, so there can be no subclass override of its methods.
Constructors
Constructors are not inherited instance methods, so they cannot be overridden. A class may define multiple constructors with different parameter lists; that is overloading.
Rank #4
Overriding interface methods and resolving defaults
A class instance method can implement a compatible abstract instance method declared by an interface. Interface default methods are inherited subject to Java’s inheritance rules, and an appropriate inherited class instance method takes precedence over an interface default.
If unrelated interfaces provide conflicting default implementations with the same signature, the implementing type must resolve the conflict by overriding the method. The class can call a particular interface default implementation explicitly with InterfaceName.super.method(). Static interface methods are not inherited.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Quick Recap
Best Value
A quick check when an override fails to compile
- Confirm the parent declaration is an instance method that the subclass inherits and can access; private methods are not overridden.
- Compare the method name and parameter types. A changed parameter list usually means you have created an overload, not an override.
- Check return-type compatibility, access level, and checked exceptions against the inherited declaration.
- Check whether the parent method is
final, or whether one declaration is static and the other is an instance method. - For interface methods, identify whether the candidate is abstract, default, or static, and check whether another inherited method or conflicting default affects the result.
- Add
@Overrideand compile again. The compiler will report when the declaration does not actually override a method.
Java overriding at a glance
- Overriding applies to inherited instance methods; calls dispatch according to the runtime object.
- A different parameter list creates an overload, not an override.
- Same-signature static methods hide rather than override one another.
- Use
@Overrideto make intent clear and catch signature mistakes. - Return types, access, checked exceptions, inheritance, and
finaldeclarations constrain whether an override is valid.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

