子类继承父类
<?php
// 子类继承父类
class Animals{
protected function Food(){
return "吃饭...";
}
protected function Sleep(){
return "睡觉中...";
}
protected function Walk(){
return "活动中...";
}
}
?>
<?php
class Dog extends Animals{
public function YellowDog(){
echo "黄色的狗3点钟".$this->Walk()."6点钟".$this->Sleep()."8点钟".$this->Food();
}
public function BlackDog(){
echo "黑色的狗4点钟".$this->Walk()."7点钟".$this->Sleep()."9点钟".$this->Food();
}
public function RedDog(){
echo "红色的狗5点钟".$this->Walk()."8点钟".$this->Sleep()."10点钟".$this->Food();
}
}
$class=new Dog();
$class->YellowDog(); echo "<br/>";
$class->RedDog(); echo "<br/>";
$class->BlackDog();
?>
清风明月本无价,近水远山皆有情。