Fatal error: Class SuperMath may not inherit from final class (Math) in E:PHPProjects est.php on line 14
- <?php
- //聲明一個final類Math
- class Math{
- public static $pi = 3.14;
- public function __toString(){
- return "這是Math類。";
- }
- public final function max($a,$b){
- return $a > $b ? $a : $b ;
- }
- }
- //聲明類SuperMath 繼承自 Math類
- class SuperMath extends Math {
- public final function max($a,$b){}
- }
- //執行會出錯,final方法不能被重寫。
- ?>
- <?php
- //聲明一個final類Math
- final class Math{
- public static $pi = 3.14;
- public function __toString(){
- return "這是Math類。";
- }
- }
- $math = new Math();
- echo $math;
- //聲明類SuperMath 繼承自 Math類
- class SuperMath extends Math {
- } //開源代碼Vevb.com
- //執行會出錯,final類不能被繼承。
- ?>
Fatal error: Class SuperMath may not inherit from final class (Math) in E:PHPProjects est.php on line 16
新聞熱點
疑難解答