Blogger Information
Blog 57
fans 0
comment 0
visits 46849
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
抽象类
藍錄的博客
Original
761 people have browsed it

实例

<?php
/**
 * 抽象类
 * 1. abstract : 抽象
 * 2. 是类又不是类,与trait相似,不能被实例化
 * 3. 抽象类必须被继承才可以使用
 */

abstract class Fruits
{
    protected $name;

    abstract public function eat();

    public function __construct($name)
    {
        $this->name = $name;
        return '构造器,实例化自动调用';
    }

}

class Apple extends Fruits
{
    protected $name ;

    public function eat()
    {
        return $this->name . '可以直接生吃';
    }
    public function __construct($name)
    {
        parent::__construct($name);
    }


}

echo (new Apple('苹果'))->eat(), '<hr>';

运行实例 »

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

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