php类私有属性的继承和重写
私有属性可以继承但不能重写class A{
public $name = 'php';
}
class B extends A{
public $name = 'java';
}
$obj = new B();
echo $obj->name; //输出java 重写了
class A{
private $name = 'php';
}
class B extends A{
private $name = 'java';
}
$obj = new B();
var_dump($obj); //php java 私有属性可以继承但不能重写
class A{
private $name = 'php';
public function showA()
{
echo $this->name;
}
}
class B extends A{
private $name = 'java';
public function showB()
{
echo $this->name;
}
}
}
$obj = new B();
$obj->showA(); //php
$obj->showB(); //java