如题,代码如下:
<?php
class employee{
private $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee{
private $sal=5000;
//重写过的方法
public function getSal(){
return $this->sal;
}
}
$manager = new Manager();
echo "PHP ".phpversion()."
";
echo $manager->getSal();
echo "
";
?>
输出结果是 5000
如果我要保护 3000 这个值,防止被子类重写, 怎么办?