子类重写父类方法

class Goods{
    public $goods_name;
    public function __construct($g_name){
        $this->goods_name = $g_name;
    }
}
class Book extends Goods{
    public $author;
    public function __construct($g_name,$a_name){
        parent::__construct($g_name);
        $this->author = $a_name;
    }
}

$book = new Book('商品','作者');
var_dump($book);

 

猜你喜欢

转载自www.cnblogs.com/xiaobiaomei/p/10087799.html