Home  >  Article  >  php教程  >  类继承和重写的区别,类继承重写区别

类继承和重写的区别,类继承重写区别

WBOY
WBOYOriginal
2016-06-13 08:46:32920browse

类继承和重写的区别,类继承重写区别

类的继承,是在父类中存在可继承的成员A,而在子类中不存在同名成员,这样该成员会被继承到子类,当子类对象访问该成员时,实际访问的是父类的对应成员。
类的重写,是在父类中存在可继承的成员A,而在子类中存在同名成员,这样该成员会被子类重写,当子类对象访问该成员时,实际访问的是子类的成员。
所以二者的区别就是,当重写的时候,访问的重写成员与父类实际上是没有关系的,而继承时访问的是父类成员。

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