<?phpclass Car { private static $speed = 10; public function getSpeed() { return self::$speed; } //在这里定义一个静态方法,实现速度累加10 public static function speedUp(){ return self::$speed+=10; }}class Bigcar extends Car{ public static function start(){ parent::speedUp(); } }$car = new Car();Car::speedUp(); //调用静态方法加速echo $car->getSpeed(); //调用共有方法输出当前的速度值echo "<br/>";echo car::speedUp();echo "<br/>";Bigcar::start();echo Bigcar::speedUp();
- 1 回答
- 0 关注
- 1551 浏览
添加回答
举报
0/150
提交
取消