Conditions for method overloading:
1. Method names are the same
2. Method parameter type, number, order at least one different
3. The return type of the method can be different because the method overload and the return type have no relationship
4. Method modifiers can be different because method overloads and modifiers have no relationship
5. Method overloads appear only in the same class
Method override (Override) Condition:
1. Must have an inheritance relationship
2. Overrides can only appear in subclasses, if there is no inheritance, there is no overwrite, only overloaded
3. The method that is overridden in a subclass must be exactly the same as the method in the parent class, that is, the method name, the return type,
Parameter list, exactly the same
4. The access rights of the subclass method cannot be less than the access rights of the parent class method
5. The subclass method cannot throw more exceptions than the parent class method, but can throw a child exception of the parent class method exception
6. Class static methods cannot be overridden by a quilt class
7. Private methods of the parent class cannot overwrite
8. The construction method of the parent class cannot be overridden and can only be called;
Overrides are for member methods, not properties, and overrides are intended to alter the behavior of the parent class.
This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1661153
Method overloading and method overrides in Java