method Overloading (Overlord). Method overloading: means that in the same class, it is allowed to have more than one method of the same name, as long as their argument list is different, regardless of the modifier and return value type (for example, constructing method overloads). 。parameter list: The number is different, the data type is different, the order is different;。Overloaded method Invocation: The JVM invokes different methods through the parameter list of the method. The above three methods are in the same class as the premise, overloadmethod Overrides (also called method overrides). Method overrides: When a method that is identical to the parent class appears in a subclass (the return value type, the method name and the parameter list are the same), overrides appear, overriding the effect. The declaration is unchanged and is re-implemented. 。 Precautions1. The subclass method overrides the parent class method and must be guaranteed to be greater than or equal to the parent class permission ( interview selection question ) 2. The subclass method overrides the parent class method, returns a value type , and the function name and argument list are identical. 3. Return value type when learning polymorphism, the subclass method overrides the parent class method, and the return value type is less than or equal to the parent class method (This is a pit note) For example, the following codePublic class Fu { Public Fu Show () { System. out. println ("Fu Show"); return new Fu (); }}Public class Zi extends fu{ @Override Public Zi Show () { System. out. println ("zi Show"); return new Zi (); }
Overloading and overwriting methods in Java (essay 01)