复制代码 代码如下:
<?
class employee{
private $sal=3000;
//protected $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
protected $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();
?>
复制代码 代码如下:
PHP 5.3.8
3000
parent's $sal 3000
复制代码 代码如下:
<?
class employee{
//private $sal=3000;
protected $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
protected $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();
?>
复制代码 代码如下:
PHP 5.3.8
5000
parent's $sal 5000
复制代码 代码如下:
<?
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(){
//这里返回的是父类的private属性.
return parent::getSal();
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
echo "<br>";
echo "parent's /$sal ".$manager->getParentSal();
?>
复制代码 代码如下:
PHP 5.3.8
5000
parent's $sal 3000
复制代码 代码如下:
<?
class employee{
private $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
protected $sal=5000;
public function getParentSal(){
return $this->sal;
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
?>
复制代码 代码如下:
PHP 5.3.8
3000
复制代码 代码如下:
<?
class employee{
protected $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
protected $sal=5000;
public function getParentSal(){
return $this->sal;
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
?>
复制代码 代码如下:
PHP 5.3.8
5000
新闻热点
疑难解答