復制代碼 代碼如下:
<?
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
新聞熱點
疑難解答