子类覆盖了父类的方法,难道当调用子类的方法的时候要先调用父类的方法,然后再调用一遍子类的方法?
<?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(){
$this->speed = parent::speedUp() + 50;
}
}
$car = new Truck();
$car->speedUp();
echo $car->speed;
重载应该是子类方法调用__call,__call调用父类方法吧,我觉得