Blogger Information
Blog 23
fans 0
comment 0
visits 13624
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
20191009
王长中的博客
Original
973 people have browsed it

实例

abstract class father
{
    protected $name;

    public function __construct($name)
    {
        $this->name = $name;
    }

    public function dog()
    {
        return $this->name;
    }
}

class son extends father
{
    public function __construct($name)
    {
        parent::__construct($name);
    }
    public function dog(){
        return $this->name;
    }
    public function get(){
     return '好嗨哦';
    }
}
$obj=new son('小黄');
echo $obj->dog(),'<br>';//返回‘小黄’;
echo $obj->get();//返回‘好嗨哦’;

运行实例 »

点击 "运行实例" 按钮查看在线实例

总结:

         1.抽象类中的构造方法不会被子类继承;

         2.抽象类不能被实例化;

         3.抽象类中的抽象方法必须在子类中全部实现;

         4.抽象类中的方法可以有参数,也可以没有参数;

         5.抽象类中的抽象方法不要花括号,语法如:abstract public function setName($value)

Correction status:qualified

Teacher's comments:总结很不错
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post