Quick revision
The short answer
To override, a method must have the same name and parameter types as the inherited method (compared after erasure for generic methods), return the same type or a subtype, with primitive return types matching exactly, and be at least as accessible. It may throw fewer, narrower or unchecked exceptions but no new or broader checked ones. Private, static and final methods are never overridden: a final method cannot be redeclared at all, while private and static methods can only be hidden or independently redeclared.
What to remember
In this answer, we went through the overriding rules and the reason behind each: callers compiled against the superclass must keep working. The override keeps the same name and parameter types, compared after erasure; it returns the same type or a subtype, with primitives matching exactly; it is at least as accessible; and it throws no new or broader checked exceptions, while unchecked ones are free. Private and static methods are only hidden or redeclared, final methods cannot be redeclared at all, and @Override makes the compiler check every rule for us.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
To override, a method must have the same name and parameter types as the inherited method (compared after erasure for generic methods), return the same type or a subtype, with primitive return types matching exactly, and be at least as accessible. It may throw fewer, narrower or unchecked exceptions but no new or broader checked ones. Private, static and final methods are never overridden: a final method cannot be redeclared at all, while private and static methods can only be hidden or independently redeclared.
Why this question is asked
Overriding is how polymorphism works in Java: a subclass replaces an inherited method, and calls through a superclass reference run the subclass version. Because so much depends on it, the compiler enforces a set of rules, and each rule exists to keep one promise: code written against the superclass must keep working with any subclass. Interviewers ask for the full list to see whether we know these rules precisely, and the best answers explain why each rule exists. In this answer, we will recap overriding, then go through name and parameters, return types, access, exceptions, and finally private, static and final methods, with code that compiles or fails for each case.
1A Quick Recap of Overriding
A method in a subclass overrides a method in a superclass, or an interface, when it replaces it for objects of the subclass. The call is chosen at run time from the actual object's class; this is called dynamic dispatch. Code like Animal a = new Dog(); a.speak(); runs Dog's speak even though the variable's type is Animal.
The reason for the rules below is simple: a caller compiled against Animal knows only Animal's method signature, its return type, its access and its declared exceptions. Whatever the subclass does must fit inside those promises, or that caller would break. Keep that idea in mind and every rule becomes easy to remember. Putting @Override on the method asks the compiler to confirm that it really overrides something.
2Same Name and Same Parameter Types
The overriding method must have the same name and the same parameter types, in the same order. Changing a parameter type creates a different method, an overload, and the original is not replaced. For generic methods the comparison is done after erasure, the step where the compiler removes type arguments, so a subclass can override void process(List<String> items) with a method taking a raw List, though that is rarely a good idea.
Notice that parameter types must match exactly; narrowing a parameter, as in save(User), is never an override, because callers holding a Repo can still pass any Object.
3Return Types: Same or Narrower
For reference types, the overriding method may return the same type or a subtype. This is called a covariant return type. It is safe because a caller expecting an Animal is happy to receive a Dog. Primitive return types and void must match exactly, because there is no subtype relation between int and long in this sense.
Covariant returns are common in practice. Object.clone() returns Object, and classes overriding it usually return their own type so callers do not need a cast.
4Access Cannot Be More Restrictive
The overriding method must be at least as accessible as the method it overrides. The order is public, then protected, then package-private (no modifier), then private. A public method cannot become protected, and a protected method can stay protected or become public.
The reason is the same promise again. A caller holding a Base can call run() from anywhere because it is public. If Sub could make run() protected, that call would suddenly be illegal for Sub objects, and the compiler cannot know which object the variable will hold.
5Checked Exceptions: Fewer or Narrower
A checked exception is one the compiler forces callers to handle or declare, such as IOException. The overriding method may declare the same checked exceptions, narrower ones (subclasses), fewer, or none. It may not add new checked exceptions or broader ones, because callers compiled against the superclass only prepared for the declared ones. Unchecked exceptions, subclasses of RuntimeException or Error, are not restricted at all.
| Aspect | Allowed in the override | Not allowed |
|---|---|---|
| Name and parameters | identical (after erasure) | different types: that is an overload |
| Return type | same, or a subtype for references | different primitive, wider type |
| Access | same or wider | narrower, such as public -> protected |
| Checked exceptions | same, narrower, fewer, none | new or broader checked exceptions |
| Unchecked exceptions | any | no restriction |
| private / static / final | only hiding or redeclaring | overriding |
6Private, Static and Final Methods
Three kinds of methods cannot be overridden. A private method is invisible to subclasses, so a subclass method with the same signature is simply a new, unrelated method; calls inside the superclass still go to the private one. A static method belongs to the class, not to an object, so it is not dispatched dynamically: a subclass static method with the same signature hides the superclass one, and which runs depends on the declared type of the expression. A final method is explicitly closed, and declaring the same signature in a subclass is a compile error.
Notice the first output. If id() had been overridable, show() would return C. Because it is private, P's code keeps calling P's version. This is useful when a class wants helper methods that subclasses cannot interfere with, and it is the reason adding @Override to C.id() would be rejected.
7Follow-up questions
Can an overriding method be synchronized when the original is not?
Yes. Modifiers like synchronized and native are not part of the signature, so an override can add or drop them. Note that synchronized is not inherited: if the superclass method is synchronized and the override is not, calls to the override are not synchronized.
Can a subclass override a method and make it abstract again?
Yes, an abstract subclass may redeclare an inherited concrete method as abstract, forcing its own subclasses to provide a new implementation. It is rare but legal, and it can be useful when the inherited behaviour is wrong for an entire branch of the hierarchy.
What about default methods in interfaces?
A class overrides a default method like any other inherited method, and the same rules apply. If a class inherits two default methods with the same signature from two interfaces, it must override the method and may call a specific one with Interface.super.method().
8Conclusion
In this answer, we went through the overriding rules and the reason behind each: callers compiled against the superclass must keep working. The override keeps the same name and parameter types, compared after erasure; it returns the same type or a subtype, with primitives matching exactly; it is at least as accessible; and it throws no new or broader checked exceptions, while unchecked ones are free. Private and static methods are only hidden or redeclared, final methods cannot be redeclared at all, and @Override makes the compiler check every rule for us.
Open with
For a method to override another, it needs the same name and the same parameter types, and for generics the comparison is done after erasure. If the parameters differ, it is an overload instead.
Then, if they want more
The return type must be the same or, for reference types, a subtype, which is a covariant return; primitive return types and void must match exactly. Access cannot be narrower: a public method has to stay public, a protected one can stay protected or become public.
For exceptions, the override can declare the same checked exceptions, narrower ones, fewer or none, but not new or broader checked exceptions; unchecked exceptions are unrestricted. All of these rules come from one idea: code written against the superclass must still work with any subclass object.
Then the methods that are not overridden at all: private methods are invisible to the subclass, so a method with the same signature is just a new method, and the superclass keeps calling its own private one.
Static methods are not dispatched dynamically; a subclass static method with the same signature hides the parent's, and which runs depends on the type used in the call. Final methods cannot be redeclared at all. I always put @Override on overrides so the compiler checks these rules for me.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "List the rules a method must follow to override another in Java, including access...": https://scrivio-interview-library.netlify.app/java/oop-principles/581e0d9f2e/