Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

List the rules a method must follow to override another in Java, including access, return type, exceptions and static or private methods.

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.

Java
class Repo { void save(Object o) { } }
class UserRepo extends Repo {
@Override void save(Object o) { } // overrides: same name, same parameter type
void save(User u) { } // overload, not an override
// @Override void save(User u) { } // error: method does not override or implement
}

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.

Java
class Animal { Animal reproduce() { return new Animal(); } int legs() { return 4; } }
class Dog extends Animal {
@Override Dog reproduce() { return new Dog(); } // OK: Dog is a subtype of Animal
// @Override long legs() { return 4; } // error: return type long is not compatible with int
}
Dog puppy = new Dog().reproduce(); // no cast needed thanks to the covariant return

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.

Java
class Base {
public void run() { }
protected void hook() { }
}
class Sub extends Base {
// @Override protected void run() { } // error: attempting to assign weaker access privileges
@Override public void hook() { } // OK: wider access is allowed
}

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.

Java
class Reader { String read() throws IOException { return ""; } }
class FileReader2 extends Reader {
@Override String read() throws FileNotFoundException { return "x"; } // OK: narrower
}
class MemReader extends Reader {
@Override String read() { return "y"; } // OK: none
}
class DbReader extends Reader {
// @Override String read() throws SQLException { return ""; } // error: SQLException not compatible
@Override String read() { throw new IllegalStateException("db down"); } // OK: unchecked
}
Overriding rules at a glance
AspectAllowed in the overrideNot allowed
Name and parametersidentical (after erasure)different types: that is an overload
Return typesame, or a subtype for referencesdifferent primitive, wider type
Accesssame or widernarrower, such as public -> protected
Checked exceptionssame, narrower, fewer, nonenew or broader checked exceptions
Unchecked exceptionsanyno restriction
private / static / finalonly hiding or redeclaringoverriding

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.

Java
class P {
private String id() { return "P"; }
static String kind() { return "P"; }
final String name() { return "P"; }
String show() { return id(); }
}
class C extends P {
String id() { return "C"; } // a new method, not an override
static String kind() { return "C"; } // hides P.kind()
// String name() { return "C"; } // error: name() in C cannot override name() in P, overridden method is final
}
P p = new C();
System.out.println(p.show()); // P: show() calls P's private id()
System.out.println(P.kind()); // P
System.out.println(C.kind()); // C: chosen by the type name, not the object

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.

What to say in the interviewAbout 80 seconds aloud

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.
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/