方法访问控制
<?php
class Car {
private $speed = 0;
public function getSpeed() {
return $this->speed;
}
protected function speedUp() {
$this->speed += 10;
}
//增加start方法,使他能够调用受保护的方法speedUp实现加速10
public function start(){
$this -> speedUp();
}
}
$car = new Car();
$car->start();
echo $car->getSpeed();
上面的例子为什么要先定义一个public方法,才定义protected方法?