摘要:<?php //定義一個父類 class Father { //靜態(tài)屬性 public static $money = 50000; //靜態(tài)方法 &
<?php //定義一個父類 class Father { //靜態(tài)屬性 public static $money = 50000; //靜態(tài)方法 public static function getClass() { //返回當前類名 return __CLASS__; } //靜態(tài)方法 public static function getMoney() { // return self::getClass().'有'.self::$money; //static 用在靜態(tài)繼承的上下文中,動態(tài)設置靜態(tài)成員的調(diào)用者(主體) return static::getClass().'有'.static::$money; } } //定義一個子類 class Son extends Father { //覆寫父類的靜態(tài)屬性 public static $money = 30000; //覆寫父類的靜態(tài)方法 public static function getClass() { return __CLASS__; } } //調(diào)用Father中的靜態(tài)方法,來獲取類名 echo Father::getClass(),'<br>'; echo Father::getMoney(),'<br>'; //調(diào)用子類Son類中的靜態(tài)成員 echo Son::$money,'<br>'; echo Son::getClass(),'<br>'; echo '<hr>'; echo Son::getMoney();
批改老師:查無此人批改時間:2019-06-06 09:33:56
老師總結(jié):完成的不錯,學習完類,就相當于php入門了。繼續(xù)加油。