幫忙看一下注釋,我這么理解對么?
<?php
class?Car
{
????private?$speed?=?0;//第一步賦值
????
????public?function?getSpeed()
????{
????????return?$this->speed;
????}
????
????protected?function?speedUp()
????{
????????$this->speed?+=?10;
????}//第三步經過運算把速度加10
????
????public?function?start()
????{
????????$this->speedUp();
????}?//第二步這里通過start進入speedup類
}
$car?=?new?Car();//定義對象
$car->start();//這個不理解。。。
echo?$car->getSpeed();//第四步找到speed輸出
2016-01-15
$car -> start()-----變量car 調用start方法,第四步并不是找到speed,它只是調用getSpeed,因為getSpeed方法里面將私有變量(private)speed變為公有的public并輸出-------return $this -> speed,私有訪問該方法的時候可以得到speed.
2016-01-15
$car->start();//對象調用方法
$car調用start()方法
2016-01-15
如果理解的不對不要噴我,我這是第二個星期