21,887
社区成员
发帖
与我相关
我的任务
分享
<?php
class employee{
private $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
private $sal=5000;
public function getParentSal(){
//这里返回的是父类的private属性.
return parent::getSal();
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
echo "<br>";
echo "parent's \$sal ".$manager->getParentSal();
?>
public function getParentSal(){
return parent::getSal();//这里调用了父类的方法,输出当然就是3000。
}
<?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;
}
public function getParentSal(){
return parent::getSal();
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
echo "<br>";
echo "parent's \$sal ".$manager->getParentSal();
?>
private $sal=3000;
public function getSal(){
return $this->sal;
}