Introduce the differences and connections between override and overload
1 Overview
1. What is overloading?
The mechanism of using formal parameters to distinguish multiple methods with the same name in the same class is called overloading.
2. What is rewriting?
The subclass inherits the parent class, and the process of overriding the parent class method is called rewriting.
Second comparison
1. Occurrence scope
Rewriting occurs between the parent class and the child Between classes, involving two classes, overloading occurs within the same class.
2. Constraint
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)