继承一个抽象类
abstract class Hero{
protected $name;
protected $ability;
public function __construct($name,$ability){
$this-> name = $name;
$this-> ability = $ability;
}
public function get_info(){
return $this->name.'的技能是:'.$this->ability;
}
abstract public function set_name($value);
abstract public function set_ability($value);
}
class stabber extends Hero{
public function __construct($name,$ability)
{
parent::__construct($name,$ability);
}
public function set_name($value){
$this-> name = $value;
}
public function set_ability($value){
$this-> ability = $value;
}
}
$hero = new stabber('韩信','国士无双');
echo $hero->get_info();
echo '<br>';
$hero ->set_name('李白');
$hero ->set_ability('青莲剑歌');
echo $hero->get_info();点击 "运行实例" 按钮查看在线实例
结果:
韩信的技能是:国士无双
李白的技能是:青莲剑歌
2. 模仿课堂案例,写一个接口实现CURD操作, 并扩展一到二个方法
总结:
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号