Overload & Override,
Overload & Overrideoverload -- Overload
Method overloading means that multiple methods with the same name but different parameters can be defined in a class. During the call, the corresponding method is selected based on different parameter tables.
Rule: two are different from three.
Two identical: the same class and the same method name
Three different: the parameter type, number, and order are different.
Note: different parameter names and different return values cannot constitute a method overload. If only the method parameter names are different or the method return value is different, the real parameters you enter when calling the method correspond to multiple methods in the parameter list, the compiler cannot know which method you actually call.
The code is described as follows:
Note: Any method overload, including constructor, is allowed in java. Therefore, to completely describe a method, you need to point outMethod NameAndParameter typeThis is called the signature of a method ).
Override ----- rewrite
Modify the methods inherited from the parent class as needed in the subclass. This is called method rewriting, or method overwrite. The override method can only exist in an inherited relationship.
Note:
(1) The subclass cannot override the Methods Modified by the keyword final in the parent class (including the private method, because the private method is implicitly final ).
(2) The rewrite method must have the same method name, parameter list, and return value type as the method to be rewritten.
(3) the method to be rewritten cannot use more strict access permissions than the method to be rewritten (because of polymorphism ). Reload.
(4) A non-checked exception can be thrown if the method to be rewritten does not throw a new exception or a broader inspection exception than the declared method to be overwritten. For example, a method of the parent class declares an IOException check. When rewriting this method, the rewrite method cannot throw an Exception, but can only throw an IOException or its subclass Exception, you can also throw a non-checked exception. You can throw different exceptions for a reload.
Method overloading does not matter with method rewriting!