Home  >  Article  >  Backend Development  >  The difference between class inheritance and overwriting, the difference between class inheritance and overwriting_PHP tutorial

The difference between class inheritance and overwriting, the difference between class inheritance and overwriting_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:59:28958browse

The difference between class inheritance and rewriting, the difference between class inheritance and rewriting

Class inheritance is that there is an inheritable member A in the parent class, but not in the child class If there is a member with the same name, the member will be inherited to the subclass. When the subclass object accesses the member, it will actually access the corresponding member of the parent class.
Class rewriting means that there is an inheritable member A in the parent class, and a member with the same name exists in the subclass, so that the member will be overridden by the subclass. When the subclass object accesses the member, the actual accessed Is a member of the subclass.
So the difference between the two is that when overriding, the overridden members accessed have nothing to do with the parent class, while when inheriting, the members of the parent class are accessed.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1098998.htmlTechArticleThe difference between class inheritance and overriding. The difference between class inheritance and rewriting is that there is a variable in the parent class. Inherited member A, but there is no member with the same name in the subclass, so the member will be inherited to the subclass...
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