3、子类可以修改和调整父类定义的类成员
<?php class Animal { private $weight; public function getWeight() { return $this->weight; } public function setWeight($w) { $this->weight = $w; } } class Dog extends Animal { /** *子类新增方法 */ public function Bark() { echo "Wang~~Wang~~~ "; } } $myDog = new Dog(); $myDog->setWeight(20); echo "Mydog's weight is ".$myDog->getWeight().'<br>'; $myDog->Bark(); ?>
原文地址:http://blog.csdn.net/zhao1234567890123456/article/details/43120919