求解这个问题,我感觉思路是对的啊
<?php
class Car {
public $speed = 0; //汽车的起始速度是0
public function speedUp() {
$this->speed += 10;
return $this->speed;
}
}
//定义继承于Car的Truck类
class Truck extends Car {
public function speedUp()
{
parent::speedUp();
return $this->speedUp() += 50;
}
}
$car = new Truck();
echo $car->speedUp();