Let’s say you have a class called “Bird” with a method called “fly” that prints out “flapping wings and flying through the air.” Now, let’s say you create 3 child classes called “Eagle,” “Hawk,” and “Penguin,” each of which extend “Bird.” The “fly” method inherited from “Bird” is fine for your “Eagle” and “Hawk” classes. But you’ll probably want to override “fly” in your “Penguin” class and make it print something like “I cannot fly.” Does that make sense? Answer from Sensitive-Bear on reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › java › overriding-in-java
Overriding in Java - GeeksforGeeks
The overridden method in the subclass must have the same name, parameters, and return type as the method in the parent class. Name, parameters, and return type must match the parent method.
Published   October 14, 2025
🌐
Oracle
docs.oracle.com › javase › tutorial › java › IandI › override.html
Overriding and Hiding Methods (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and then to modify behavior as needed. The overriding method has the same name, number and type of parameters, and return type as the method that it overrides.
Discussions

Why do we need function overriding?
Let’s say you have a class called “Bird” with a method called “fly” that prints out “flapping wings and flying through the air.” Now, let’s say you create 3 child classes called “Eagle,” “Hawk,” and “Penguin,” each of which extend “Bird.” The “fly” method inherited from “Bird” is fine for your “Eagle” and “Hawk” classes. But you’ll probably want to override “fly” in your “Penguin” class and make it print something like “I cannot fly.” Does that make sense? More on reddit.com
🌐 r/java
24
7
June 30, 2021
Why use Method Overriding in java - Stack Overflow
I'm currently learning about Java and I encountered this particular function called method overriding. When do I need to override something from the parent class if I can just create a new function? More on stackoverflow.com
🌐 stackoverflow.com
method overriding in Java - Stack Overflow
How is method overriding implemented in Java? In C++ we have the concept of vtable.. how is this implemented internally in Java? More on stackoverflow.com
🌐 stackoverflow.com
Please explain how overloading and overriding methods works in Java
Overloading is when you have multiple method signatures for the same method - i.e. you can call a method in several different ways. You might for example have a method with the signature GetTransactions(int customerId) to look up transactions by customer ID, but then also a GetTransactions(int[] customerIds) to pass in multiple customer IDs. Overriding is when a method in a derived class effectively "replaces" a method in a base class. For example let's say you had an Employee base class with a Work method defined on it. You then derive a Manager class from Employee and override the Work method to do some different things, as a manager's job is going to be different. More on reddit.com
🌐 r/learnprogramming
2
2
February 15, 2023
🌐
Tutorialspoint
tutorialspoint.com › java › java_overriding.htm
Java - Overriding
The benefit of overriding is: ability ... on its requirement. In object-oriented terms, overriding means to override the functionality of an existing method....
🌐
BeginnersBook
beginnersbook.com › 2014 › 01 › method-overriding-in-java-with-example
Method overriding in java with example
Yes we can change but, return type can be either same or sub type of the super class method return type that is called as a covariance (introduced from java 1.5) ... no we can not change if we change the return type of parameter then we will get compile time error in method overloading we have change the parameter but it must same method name . in method overridding we don’t change datatype ,return type and sequence of parameter it should be as super class but we just change logic/implimentation
🌐
Programiz
programiz.com › java-programming › method-overriding
Java Method Overriding
In this tutorial, we will learn about method overriding in Java with the help of examples. If the same method defined in both the superclass class and the subclass class, then the method of the subclass class overrides the method of the superclass. This is known as method overriding.
🌐
Vlabs
java-iitd.vlabs.ac.in › exp › method-overriding › theory.html
Method Overriding in Java - Virtual Labs
Method overriding is one of the way by which java achieve Run Time Polymorphism. Method overriding is used to provide the specific implementation of a method which is already provided by its superclass. Method overriding is used for runtime polymorphism. The method must have the same name as ...
🌐
Medium
medium.com › @nakulmitra2114 › method-overriding-in-java-cd3fcea6bd82
Method Overriding in Java. Method overriding is a fundamental… | by Nakul Mitra | Medium
3 weeks ago - Method overriding is an essential feature in Java that allows subclasses to modify the behavior of inherited methods, enhancing the flexibility and modularity of your code.
Find elsewhere
🌐
Reddit
reddit.com › r/java › why do we need function overriding?
r/java on Reddit: Why do we need function overriding?
June 30, 2021 -

I was asked to write a program on overriding , 3 classes with add methods where one added integers , other string and the other subtracted(name was still add).

If we are gonna write the function definition and another class then what is the purpose of overriding.

And is there any way to just call all the three add methods from the instance of one of the classes?

Top answer
1 of 7
28
Let’s say you have a class called “Bird” with a method called “fly” that prints out “flapping wings and flying through the air.” Now, let’s say you create 3 child classes called “Eagle,” “Hawk,” and “Penguin,” each of which extend “Bird.” The “fly” method inherited from “Bird” is fine for your “Eagle” and “Hawk” classes. But you’ll probably want to override “fly” in your “Penguin” class and make it print something like “I cannot fly.” Does that make sense?
2 of 7
3
There are two similarly looking and similarly named concepts: method overriding and method overloading. To get the difference we need to talk about method signatures. This includes the method name, the number, type and position of the parameters. Method overriding is when you have a method, specified in a parent class or interface is (re)implemented in its sub-classes. These methods must have the same signatures and the same[1] return types. This is what is used to implement polymorphism in Java, as the other answers explain. Method overloading is when you have two methods with the same name but with different signatures. They can even be in the same class: interface A { void operation(String s); void operation(String s1, String s2); void operation(int i, float f); } This is mostly done for having a more readable code. Without it you wouldn't be allowed to have 2 or more different methods sharing the same name. ---- [1] Or compatible ones. For example: class A { Number add(Number a, Number b) { // ... } } class B extends A { @Override Integer add(Number a, Number b) { // This is OK, because Integer extends Number } }
🌐
Simplilearn
simplilearn.com › home › resources › software development › method overriding in java: essential rules and examples
Method Overriding in Java: Essential Rules and Examples
June 9, 2025 - Discover the key rules and examples of method overriding in Java, a crucial concept for achieving polymorphism and dynamic process execution.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Educative
educative.io › answers › what-is-method-overriding-in-java
What is method overriding in Java?
For method overriding, the method must have same name and same type signature in both the superclass and the subclass. To accomplish Java runtime polymorphism, overriding methods are utilized.
🌐
Unstop
unstop.com › home › blog › method overriding in java | rules, use-cases & more (+codes)
Method Overriding In Java | Rules, Use-Cases & More (+Codes)
November 11, 2024 - When the subclass redefines a method it inherited from the parent/ superclass, it is known as method overriding in Java. You must follow a set of rules for this.
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-method-overloading-and-method-overriding-in-java
Overloading vs Overriding in Java - GeeksforGeeks
Explanation: The my_Sum method is overridden in the child class. At runtime, Java determines which version to call based on the actual object. Calling my_Sum(5, 10) on a Calculator object uses the parent class method, while calling it on an ...
Published   October 14, 2025
Top answer
1 of 4
2

If you make a new method bark for your Dog class instead of overriding speak, then you also have to add code to detect that youre dealing with a dog, then cast it to a Dog type, then call bark. You get a program that has a bunch of very specific code that has to handle each concrete type individually, and the workflow has to be updated every time you add a new subclass. There is no abstraction or generality.

The idea behind polymorphism is that your program shouldn't have to worry about which objects are dogs and which are cats, it just handles animals, and lets the subclasses take care of the details for themselves. The program stays at a high level and tells the animals to speak, the specific animals' subclasses decide whether to bark or meow. So if you introduce a new animal subclass the code handling animals doesn't change.

2 of 4
0

You override a method when you have a class hierarchy, as you do, where there is a sensible default behaviour which many of your subclasses will want to use, but some subclasses need different behaviour and you want to call the method using a reference of the base class.

If I had code like:

Dog d = new Dog();
d.speak();

Then just implementing bark() would be fine, because d is always a Dog. But when I have code like this:

Animal a;
if (...) {
 a = new Dog();
} else {
 a = new Cat();
}
a.speak();

Then we have to override a method. If the subclasses had a new method (like your bark()) which wasn't present on Animal we wouldn't be able to call it, because a is an Animal -- the actual object it refers to might be a Dog or a Cat.

🌐
W3Schools
w3schools.in › java › method-overriding
Java Method Overriding - W3Schools
Declaring a method in the subclass which already exists there in the parent class is known as method overriding.
Top answer
1 of 6
14

To answer the question, which is specifically how overriding is implemented in the virtual machine, there's a write up available in Programming for the Java Virtual Machine (Google Books link).

The VM will look for an appropriate method definition in the referenced class, and then work its way up through the inheritance stack. Obviously at some stage various optimisations will apply.

See here for a description of the relevant bytecode instruction invokevirtual:

invokevirtual looks at the descriptor given in , and determines how many arguments the method takes (this may be zero). It pops these arguments off the operand stack. Next it pops objectref off the stack. objectref is a reference to the object whose method is being called. invokevirtual retrieves the Java class for objectref, and searches the list of methods defined by that class and then its superclasses, looking for a method called methodname, whose descriptor is descriptor.

As gustafc has highlighted below, various optimisations can apply, and no doubt the JIT will introduce further.

2 of 6
1

Method overriding in Java is a concept based on polymorphism OOPS concept which allows programmer to create two methods with same name and method signature on interface and its various implementation and actual method is called at runtime depending upon type of object at runtime. Method overriding allows you to write flexible and extensible code in Java because you can introduce new functionality with minimal code change.

There are few rules which needs to be followed while overriding any method in Java, failure to follow these rules result in compile time error in Java.

  1. First and most important rule regarding method overriding in Java is that you can only override method in sub class. You can not override method in same class.
  2. Second important rule of method overriding in Java that name and signature of method must be same in Super class and Sub class or in interface and its implementation.
  3. Third rule to override method in Java is that overriding method can not reduce accessibility of overridden method in Java. For example if overridden method is public than overriding method can not be protected, private or package-private; But opposite is true overriding method can increase accessibility of method in Java, i.e. if overridden method is protected than overriding method can be protected or public.
  4. Another worth noting rule of method overriding in Java is that overriding method can not throw checked Exception which is higher in hierarchy than overridden method. Which means if overridden method throws IOException than overriding method can not throw java.lang.Exception in its throws clause because java.lang.Exception comes higher than IOException in Exception hierarchy. This rule doesn't apply to RuntimeException in Java, which is not even need to be declared in throws clause in Java.
  5. You can not override private, static and final method in Java. private and static method are bonded during compile time using static binding in Java and doesn't resolve during runtime. overriding final method in Java is compile time error. Though private and static method can be hidden if you declare another method with same and signature in sub class.
  6. Overridden method is called using dynamic binding in Java at runtime based upon type of Object.
  7. If you are extending abstract class or implementing interface than you need to override all abstract method unless your class is not abstract. abstract method can only be used by using method overriding.
  8. Always use @Override annotation while overriding method in Java. Though this is not rule but its one of the best Java coding practice to follow. From Java 6 you can use @Override annotation on method inherited from interface as well.
🌐
Javatpoint
javatpoint.com › method-overriding-in-java
Method Overriding in Java - javatpoint
Method Overriding in Java. Java method overriding is used for providing specific implementation and runtime polymorphism, difference between method overloading and method overriding in java.
🌐
Reddit
reddit.com › r/learnprogramming › please explain how overloading and overriding methods works in java
r/learnprogramming on Reddit: Please explain how overloading and overriding methods works in Java
February 15, 2023 -

I am trying to make sense of both of these and was wondering if someone had an interesting way of understanding it. It seems like a bizarre thing to have possible.

Top answer
1 of 2
4
Overloading is when you have multiple method signatures for the same method - i.e. you can call a method in several different ways. You might for example have a method with the signature GetTransactions(int customerId) to look up transactions by customer ID, but then also a GetTransactions(int[] customerIds) to pass in multiple customer IDs. Overriding is when a method in a derived class effectively "replaces" a method in a base class. For example let's say you had an Employee base class with a Work method defined on it. You then derive a Manager class from Employee and override the Work method to do some different things, as a manager's job is going to be different.
2 of 2
4
I can have two methods called addNumbers. One requires two parameters (int x, int y) I can have another method, ALSO called addNumbers. This version requires THREE parameters. (Int x, int y, int z) They are called the same method NAME but because I pass different parameters… Java will know which one I want to use. Thus, it’s name is overloaded. Overridden is to change the way an inherited method behaves, even if it returns the same type. Classic example is class Shape. Shapes have area, and so a method that returns a double representing that value is common. So shapes class has that. Subclass Square inherits that method, but calculates it with length x width. A different subclass Circle also inherits calculateArea, but the math is very different. So even though the method behaves and performs the same task, it DOES so very differently. That is overriding. Keeping the same behavior, but modifying HOW you do the thing in the method. Hope this helps!
🌐
Tpoint Tech
tpointtech.com › method-overriding-in-java
Method Overriding in Java - Tpoint Tech
March 17, 2025 - Method Overriding in Java is used to achieve runtime polymorphism and dynamic behavior.
🌐
ScholarHat
scholarhat.com › home
Explore the Concept of Overriding in Java
September 9, 2025 - Overriding in Java allows a subclass to provide a specific implementation of a method declared in its parent class. It supports runtime polymorphism, which ensures that the method called corresponds to the object's real type rather than the ...