☕ Java Beginner

What is method overriding in Java?

Why Interviewers Ask This

This is a classic screening question for Java roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

Method overriding is when a subclass provides its own implementation of a method already defined in its superclass, with the same method signature (name, parameter types, and return type). The overriding method is selected at runtime based on the actual object type — this is runtime (dynamic) polymorphism. The @Override annotation is not mandatory but strongly recommended as it causes a compile error if the method does not actually override anything. Rules: you cannot override static, final, or private methods. The overriding method cannot have a more restrictive access modifier.

Common Mistake

Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Java project.