<?
class bird{
private $color;
private $chibang;
private $zhuazi;
private $yumao;
const gold='0.618';
function __construct(){
echo "[Construct parent]I Can Fly";
}
function fly(){
echo "I really Can Fly"."<br/>";
}
final function sound(){//只能修饰成员方法 和 类
echo "I Like SingSong";
}
static function dance(){
echo "I Like Dance";
}
}
class chicken extends bird{
private $color;
private $chibang;
private $zhuazi;
private $yumao;
protected $giveegg;
function __construct(){
echo "[Construct self]Not only i am a bird(chicken),but also i can't fly"."<br/>";
self::fly();//在自身调用方法//作用域
}//重载
function fly(){
echo "Not only i am a bird(chicken),but also i can't fly"."<br/>";
parent::fly();//在重载子类里访问父类被重载方法//作用域
}
function high(){
echo $this->giveegg='twenty_egg';
}
}
$chicken=new chicken;
echo "<pre>";
var_dump($chicken);
echo "</pre>";
echo "<br/>";
echo "<hr/>";
$chicken->fly();
echo bird::sound();//final只能修饰成员方法 和 类 //限制类的继承 方法的覆盖
echo bird::gold;//常量的输出使用作用域
echo "<hr/>";
$chicken->high();//protected类内调用
echo "<hr/>";
echo chicken::dance();
09-24 code
最新推荐文章于 2013-10-28 20:34:55 发布