What's the difference between redefining a method and overriding a method?
I've never heard of "redefine" as an OO term as applied to Java.
However, the example you give is not overriding, because static methods are not inherited, but are statically dispatched based on the type of the variable (as opposed to the dynamic dispatch that occurs with member methods).
I wouldn't call it a redefinition, though - you had a method called DonkeyBattler.doBattle
, and you've now defined a compiletely separate method called FunkyBattler.doBattle
.
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.
Intention of overriding is actually Redefining the inherited method from the parent class.
Redefining involves:
Replacement
1. **Replacement** is the case in which child class is overriding
The inherited method of parent class with a behavior(functionality) which is completely different from corresponding parent method and a sign for this process is not calling super.method() in the body of child method.
Refinement
2. Refinement is the case in which child is overriding inherited
The method from parent with a functionality related to parent method functionality, sign of this process is calling generally super.method() in the body of child method.