search
HomeJavajavaTutorialIntroduce 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

  1. subclass in When overriding a parent class method, the return value must be a subclass of the parent class method's return value.

  2. 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.

  3. # The exception thrown must be a subclass of the parent exception.

  4. # Static methods cannot be overridden.

  5. #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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

MantisBT

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 new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)