<?php class Car { public $speed = 0; //汽车的起始速度是0 public function speedUp() { $this->speed += 10; return $this->speed; } } class Truck extends Car { public function speedUp() { $this->speed = parent::speedUp() + 50; } } //定义继承于Car的Truck类 $car = new Truck(); $car->speedUp(); echo $car->speed;
原来对象都有继承关系的啊!