The mechanism of using formal parameters to distinguish multiple methods with the same name in the same class is called overloading.
The subclass inherits the parent class, and the process of overriding the parent class method is called rewriting.
Rewriting occurs between the parent class and the child Between classes, involving two classes, overloading occurs within the same class.
Override
subclass in When overriding a parent class method, the return value must be a subclass of the parent class method's return value.
The access permission of the parent class cannot be reduced, that is, if the access permission of the parent class method is protected, the subclass cannot change it to private when overriding the method.
# The exception thrown must be a subclass of the parent exception.
# Static methods cannot be overridden.
#Final type methods cannot be overridden.
Overloading
Overloading distinguishes methods with the same name based on their formal parameters, so formal parameters between methods with the same name They cannot be exactly the same. The parameter types and numbers are exactly the same, but the order is different, and they belong to different formal parameters.
The above is the detailed content of Introduce the differences and connections between override and overload. For more information, please follow other related articles on the PHP Chinese website!