search
Homephp教程php手册方法重载和重写的区别 - favana

答一:
根本区别:
重写(重构)很直观啊,子类覆盖了父类的同名同参同返回值的方法,用子类调用的只会是重写的方法
重载,同名而已。
 
 
答二:
1、重载:
方法名相同,参数列表不同
2、重写:
也叫覆盖,指在子类中定义一个与父类中方法同名同参数列表的方法。因为子类会继承父类的方法,而重写就是将从父类继承过来的方法重新定义一次,重新填写方法中的代码。
 
 

答三:
 
重写是子类的<a class="baidu-highlight" href="https://www.baidu.com/s?wd=%E6%96%B9%E6%B3%95%E8%A6%86%E7%9B%96&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4rHwhuAfYP164myfzmW0z0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHDzrHcdrjb" rel="nofollow" target="_blank">方法覆盖</a>父类的方法,要求方法名和参数都相同<br /><br />重载是在同一个类中的两个或两个以上的方法,拥有相同的方法名,但是参数却不相同,方法体也不相同,最常见的重载的例子就是类的<a class="baidu-highlight" href="https://www.baidu.com/s?wd=%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4rHwhuAfYP164myfzmW0z0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHDzrHcdrjb" rel="nofollow" target="_blank">构造函数</a>,可以参考<a class="baidu-highlight" href="https://www.baidu.com/s?wd=API&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4rHwhuAfYP164myfzmW0z0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHDzrHcdrjb" rel="nofollow" target="_blank">API</a>帮助文档看看类的<a class="baidu-highlight" href="https://www.baidu.com/s?wd=%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4rHwhuAfYP164myfzmW0z0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHDzrHcdrjb" rel="nofollow" target="_blank">构造方法</a><br /><br /><br /><br />
答四:

1.重写必须继承,重载不用。
2.重写的方法名,参数数目相同,参数类型兼容,重载的方法名相同,参数列表不同。
3.重写的方法修饰符大于等于父类的方法,重载和修饰符无关。
4.重写不可以抛出父类没有抛出的一般异常,可以抛出运行时异常
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 Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor