Blogger Information
Blog 28
fans 0
comment 0
visits 16426
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
子类重载父类--2018年05月06日20:15
植树青年小江同志的博客
Original
630 people have browsed it

父类部分


实例


<?php

class Vehicle
{
  protected $country;
  protected $brand;
  protected $displacement;
  protected $price;

  public function __contruct($brand, $model, $displacement, $price)
  {
    $this->country = $country;
    $this->brand = $brand;
    $this->displacement = $displacement;
    $this->price = $price;
  }

  public function engineStart()
  {
    return '发动机启动';
  }
}

运行实例 »

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



子类部分


实例

<?php

require './Vehicle.php';

class Roderster extends Vechile
{
  private $door = 2;
  private $seat = 2;

  // 必须使用构造方法对使用当前新增属性生效
  public function __construct($country, $brand, $model, $displacement, $price, $door, $seat)
  {
    // 调用父类构造器初始化类属性
    parent::__construct($country, $brand, $model, $displacement, $price);

    $this->door = $door;
    $this->seat = $seat;
  }

  public function catchGirl()
  {
    return '带上小姐姐';
  }

  public function engineStart()
  {
    return parent::engineStart(). '声音悦耳;';
  }
}


运行实例 »

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


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!