php专区

 首页 > php专区 > PHP高级 > 面向对象MVC > PHP 面向对象 final类与final方法

PHP 面向对象 final类与final方法

分享到:
【字体:
导读:
          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 f...

Fatal error: Class SuperMath may not inherit from final class (Math) in E:PHPProjects est.php on line 14

  1. //声明一个final类Math  
  2. class Math{  
  3. public static $pi = 3.14;  
  4. public function __toString(){  
  5. return "这是Math类。";  
  6. }  
  7. public final function max($a,$b){  
  8. return $a > $b ? $a : $b ;  
  9. }  
  10. }  
  11. //声明类SuperMath 继承自 Math类  
  12. class SuperMath extends Math {  
  13. public final function max($a,$b){}  
  14. }  
  15. //执行会出错,final方法不能被重写。 
  16.  
  17. ?>  
  18. //声明一个final类Math  
  19. final class Math{  
  20. public static $pi = 3.14; 
  21.  
  22. public function __toString(){  
  23. return "这是Math类。";  
  24. }  
  25. }  
  26. $math = new Math();  
  27. echo $math
  28.  
  29. //声明类SuperMath 继承自 Math类  
  30. class SuperMath extends Math {  
  31. //开源代码phpfensi.com 
  32. //执行会出错,final类不能被继承。 
  33.  
  34. ?> 

Fatal error: Class SuperMath may not inherit from final class (Math) in E:PHPProjects est.php on line 16

 
 
分享到:
让PHP开发者事半功倍的十大技巧
1、如何正确的创建一个网站的Index页面 创建每一个网站时,建立网站的index页面是首要做的事情之一。如果你是一个PHP新手,在编写index页面时典型的做法是只对index页面所需的内容进行编程,其它链接创建另一个页面。不过,如果想学习一种更高效的方式来实现PHP编程,可以采用“index.php?page=home”模式,许多网站都...
PHP5 中的常量 PHP 面向对象
在PHP5中 const定义的常量与定义变量的方法不同,不需要加 $ 修饰符,const PI = 3.14; 这样就可以. 而使用const 定义的常量名称一般都大写,这是一个约定,在任何语言中都是这样. 如果定义的常量由多个单词组成,使用 _ 连接,这也是约定. 比如,MAX_MUMBER 这样的命名方式,一个良好的命名方式,是程序员必须注意的,类...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……