What's the difference between redefining a method and overriding a method?

java

Solution

The term "redefinition" isn't usually used with regards to Java methods and inheritance. There are two terms that are commonly used: "override" as you said, and "overload." To overload in Java is to create two methods in the same class with the same name but different signatures (number and/or types of arguments). For example:

public interface MyInterface
{
    public int doStuff(int first, int second);
    public int doStuff(double only);
}

To override is to do something like what you are doing in your example: create a child class with a method that has the same name and signature as a method in the parent class that will be used for all instances of the child class but not of the parent class or any other child classes of that parent.

The only issue with your example as it relates to overloading is the use of the keyword `static`. Overriding is determined dynamically, but static methods by definition are not.

Problem

``` class DonkeyBattler { static void doBattle(){ System.out.println("Weaponized donkey battling"); } } class FunkyBattler extends DonkeyBattler { static void doBattle(){ System.out.println("Weaponized donkey battling with bellbottoms"); } } ``` doBattle method is supposed to be a redefinition or an override? Oh this is Java by the way.

Original source