亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

利用后期靜態(tài)綁定技術,實現(xiàn)在父類調(diào)用子類中重寫的靜態(tài)成員

original 2019-03-26 15:30:03 254
abstrait:<?php echo '<h3>類的繼承和代碼復用</h3>'; class Father { public $name; protected $age; private $salary; public static $sex = 'male';
<?php
echo '<h3>類的繼承和代碼復用</h3>';
class Father
{
public $name;
protected $age;
private $salary;
public static $sex = 'male';
public function __construct($name,$age,$salary)
{
$this->name = $name;
$this->age = $age;
$this->salary = $salary;
}
public function play($play)
{
return $this->name.' 在 '.$play;
}
//private method
private function save()
{
return $this->salary.'save the money!';
}
public function getAge()
{
return $this->age;
}
public static function getClass()
{
return __CLASS__;
}
public static function getInfo()
{
return static::$sex.' and '.static::getClass();
}
}
class Son extends Father
{
//subclass rewirte father method
public static $sex = 'famale';
public static function getClass()
{
return __CLASS__;
}
public function play($play)
{
echo $this->name.'<br>';
return $this->name.' is do : '.$play.parent::$sex;
}
}
$father = new Father('Fming',42,10000);
$son = new Son('sming',21,5000);
echo 'attribute extends: '.$son->name.'--'.$son->getAge().'<br>';
echo 'method extends: '.$son->play('is running!').'<br>';
echo $father->play('working').'<br>';
echo Father::getInfo().'<br>';
echo Son::getInfo().'<br>';

幾個小例子合在一起寫的

Professeur correcteur:天蓬老師Temps de correction:2019-03-26 16:52:15
Résumé du professeur:重載主要是指方法, 方法的重載, 提供一種容錯機制, 向用戶提供了友好的訪問接口

Notes de version

Entrées populaires