求解這個問題,我感覺思路是對的啊
<?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();
2016-11-16
你得到的值會是50 因為沒有調(diào)用父類中的10這個值 所以得到的是50
2016-07-23
你的繼承Truck,并沒有用到上面的屬性和函數(shù),也就是上面的speed在Truck中并沒有用到
2016-04-24
?? parent::speedUp();
??????? return $this->speed += 50;
這樣子寫
2016-04-13
?return $this->speedUp() += 50;這句有問題,前面已經(jīng)用Parent來調(diào)用了父類speedUP()方法。但是沒有將+=50指向給$speed這個變量。
2016-04-12
$this->speed = parent::speedUp()+50;要定義在父類的基礎(chǔ)上操作 加parent
2016-04-12
return $this->speedUp() += 50;這里 有問題
2016-04-12
return貌似有點問題