I. Method Overloading (OVERLOAD)
/* Method overload judgment: In the same class, the method name is the same, the parameter list is different (the number of parameters is different, the parameter list corresponds to the position parameter type), the other method return value * and access modifiers are arbitrary. */public class Overloadtest {public void testFunc (int a, int b, float c) {}//The first situation:the number of Param tabl E is different.public void TestFunc (int a, int. b) {}//The second situation:the type of param table is different.//parameter type The meaning is that: The parameter list corresponds to the type of position, and the parameter name is not any connection, so in the process of judging the method overload//regardless of the parameter order changes. public void TestFunc (int A, float c, int b) {}/* * the following function isn ' t overload *///error Message: Duplicate method Testfun c (int, int, float) in type overloadtest//with the first method repeated the error, because the parameters A and B are the same type, regardless of whether the parameter order is changed, and finally in the process of the method record,//or will be recorded as the above error message prompts, This parameter list is identical to the argument list of the first function. public void TestFunc (int b, int A, float c) {}//error message: Duplicate method TestFunc (int, float, int) in type overloadtest//although the The function also exchanges the parameter order, but the exchange of the two parameter types are different, resulting in a parameter list corresponding to the method one location type,//and method one did not cause duplicate error, but with method three has caused repeated error, should be for their parameter list is (int, float, int). It can also be seen from here that the parameter names are not considered in the decision of the method overload. public void TestFunc (int A, float c, int b) {}}
Two. Method overrides (Overwrite)
Method overrides are also called method overrides, which indicate that subclasses want to modify a method of a parent class, and the method overrides are simple and generally follow the following guidelines:
1. Two same as: Method name and method parameter list
2. One large: Overridden method in a subclass has greater access than equals to a method in the parent class
3. Two small: An overriding method in a subclass throws an exception type that is less than or equal to the parent class; The return value type of an overriding method in a subclass is less than or equal to the parent class
Method overloading and overrides in Java (overwrite)