Blogger Information
Blog 48
fans 3
comment 1
visits 37454
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
类的继承与重载父类方法——2018年5月3日
JackBlog
Original
728 people have browsed it


随着php教学的深入,我感觉越来余越深奥了,每天做作业的时间也更长了!敲得遍数更多了!加油



1.png

实例

<?php
spl_autoload_register(function ($ClassName){
   require  './class/'.$ClassName.'.php';
});

$road = new Point('清源路黄海路',4,12,true,false,true);
echo '管理员:'.$road->admin().'<br>';
echo '路口名称:'.$road->roadName.'<br>';
echo '方向数:'.$road->direction.'<br>';
echo '车道数:'.$road->lane.'<br>';
echo '是否有抓拍机:'.($road->camera ? '有':'无').'<br>';
echo '是否有球机:'.($road->ball ? '有':'无').'<br>';
echo '是否有信号机:'.($road->signal ? '有':'无').'<br>';

运行实例 »

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

实例

<?php
/医院
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/4
 * Time: 17:26
 */

class Road
{
    protected $roadName = '';//路口名称
    protected $direction = 0;//方向数
    protected $lane = 0;//车道数
    function __construct($roadName,$direction,$lane)
    {
        $this->roadName = $roadName;
        $this->direction = $direction;
        $this->lane = $lane;
    }

    function admin()
    {
        return '周杰';
    }

}

运行实例 »

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

实例

<?php
/医院
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/4
 * Time: 17:29
 */

class Point extends Road
{
    private $camera = false; //是否有相机
    private $ball = false; //是否有球机
    private $signal = false; //是否有信号机
    function __construct($roadName, $direction, $lane, $camera,$ball,$signal)
    {
        parent::__construct($roadName, $direction, $lane);
        $this->camera = $camera;
        $this->ball = $ball;
        $this->signal = $signal;
    }
    function __get($name)
    {
        return $this->$name;
    }

    function admin()
    {
        $admin = '张宏强,周杰';
        return $admin;
    }
}

运行实例 »

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


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