[PHP] PHP面向对象 final类和方法 final类不能被继承 →→→→→进入此内容的聊天室

来自 , 2019-08-23, 写在 PHP, 查看 126 次.
URL http://www.code666.cn/view/0ebf1972
  1. <?
  2. //声明一个final类Math
  3. final class Math{
  4.       public static $pi = 3.14;
  5.      
  6.       public function __toString(){
  7.           return "这是Math类。";
  8.       }
  9. }
  10. $math = new Math();
  11. echo $math;
  12. //声明类SuperMath 继承自 Math类
  13. class SuperMath extends Math {
  14. }
  15. //执行会出错,final类不能被继承。
  16. ?>
  17.  

回复 "PHP面向对象 final类和方法 final类不能被继承"

这儿你可以回复上面这条便签

captcha