Current location - Recipe Complete Network - Complete recipe book - What is the difference between method overriding and method overloading? Can overloading change the return value type? What are the precautions?
What is the difference between method overriding and method overloading? Can overloading change the return value type? What are the precautions?

Method rewriting:

The method declared in the subclass is exactly the same as the method declared in the parent class.

Method overloading:

In the same class, methods with the same method name and different parameter lists appear.

It has nothing to do with the return value.

Overloading can change the return value type because it has nothing to do with the return value.

Notes on rewriting:

(1) Private methods in the parent class cannot be overridden

(2) Access permissions for subclass methods must be Access rights greater than those of the parent class

(3) Static methods can only be overridden by static methods. This is not actually an object relationship.