×

面向对象编程

PHP面向对象——抽象基类

feihu1996 feihu1996 发表于2018-08-04 17:52:10 浏览246 评论0

抢沙发发表评论

<?php
/*
* @file: example14.php
* @brief: PHP面向对象——抽象基类
* @author: feihu1996.cn
* @date: 下午16:25 18-8-4
* @version: 1.0
*/

abstract class A{
    /*
    定义为抽象的类不能被实例化
    */

    public function eat(){
        echo "eating ...";
        echo "\r\n";
    }

    public function sleep(){}
}

class B extends A{
    public function sleep(){
        echo "sleeping ...";
        echo "\r\n";
    }
}

$ins = new B();
$ins->eat();
$ins->sleep();

群贤毕至

访客