请大神过来看看我这样理解的对吗?
<?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();//创建的对象里面能够访问的方法只有getSpeed()和start(),此时速度为0
$car->start();//调用方法start(),而start()可以访问私有方法speedUp(),此时速度为10
echo $car->getSpeed();//最后调用可以访问的公有方法来获取当前速度,最后输出为10.