Contrasting method overriding and method overloading
These two terms are often confused but in this section, we will compare and contrast both. We will show that concerning method overloading, the method signature must be different; whereas concerning method overriding, the method signature must be the same. Recall that the method signature consists of the method name and the parameter types, including their order. The return type and the parameter identifiers are not part of the method signature. So, for example, take the method from Figure 9.5:
public static void doAction(Vehicle v){…}
The signature is doAction(Vehicle)
.
With this in mind, we will initially discuss method overloading.
Method overloading
Recall that the method signature consists of the method name and the parameter types. Method overloading is where you have the same method name but the parameters differ, either in type and/or order. This means that the method signatures are different even though...