1. Overloading
The same class is allowed for multiple methods with the same name but with a different number of formal parameters or parameter types, and the corresponding method is called according to the formal parameter list when called.
2. Judging
(1): The method name must be the same.
(2): The number of formal parameters or different types of parameters (satisfy one of the conditions on the line).
3. Rewrite
The polymorphism between the parent class and the child class, the function of the parent class is redefined, and a method defined in the subclass has the same name and parameters as its parent class, which can be called the method is overridden or overwritten.
4. Judging
(1): Access modifier permissions must be greater than the overridden method. (The overridden method cannot be overridden when it is private).
Permissions: Public>protected>default>private
(2): When the overridden method is final, it cannot be rewritten if the compilation will error.
(3): The return value type must be the same.
(4): The parameter list must be exactly the same as the method being overridden.
(5): The overriding method must not throw a new check exception or a more generic check exception than the overridden method declaration
For example: A method of the parent class declares a check exception ioexception, in overriding this method is not able to throw exception, can only throw IOException subclass exception, can throw non-check exception.
Comprehensive: With the same method name, return type, and parameter table, it will be overridden
Note: You can use the Super keyword, which refers to the parent class of the current class, if you want a method from the parent class
The difference between overloading and overriding in Java