对象php继承
class person{
private $name;
private $age;
<code> public function __construct($name,$age){ $this->name = $name; $this->age = $age; } public function show(){ echo $this->name."||".$this->age; }}class Child extends Person{}$child = new Child("aaa",5);$child->show();</code>?>
为什么会打印出 aaa||5
子类不是应该继承了父类的show()方法,然后父类方法中的$this不是应该指的是子类的对象实例吗
但是子类继承的时候应该没有继承到父类的private成员属性
所以为什么能打印出东西???
立即学习“PHP免费学习笔记(深入)”;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号