<?phpclass Car {? ? private static $speed = 10;? ??? ? public function getSpeed() {? ? ? ? return self::$speed;? ? }? ??? ? //在這里定義一個靜態(tài)方法,實現(xiàn)速度累加10? ? public static function speedUp(){? ? ? ? return self::$speed+=10;? ? }}class Bigcar extends Car{? ? ? ? public static function start(){? ? ? ? ? ? parent::speedUp();? ? ? ? }? ? }$car = new Car();Car::speedUp();? //調(diào)用靜態(tài)方法加速echo $car->getSpeed();? //調(diào)用共有方法輸出當(dāng)前的速度值echo "<br/>";echo car::speedUp();echo "<br/>";Bigcar::start();echo Bigcar::speedUp();
- 1 回答
- 0 關(guān)注
- 1586 瀏覽
添加回答
舉報
0/150
提交
取消