php面向对象之final的应用
2024-10-10 02:29:56
final从英文字面上很容易理解,翻译成中文就是“最终的”之意。在php面向对象编程中,final的应用主要有两个作用:
1、使用final修饰的类,该不能被继承
|
程序运行结果:Fatal error: Class student may not inherit from final class (Person) in D:\PhpServer\wamp\www\phptest\parent.php on line 17
父类Person被final修饰后,即为最终版本,不能有子类,也不能对其进行扩展,你只能老老实实去引用它。
2、在类中被final修饰的成员方法,在子类中不能被覆盖
为防止子类扩展父类的方法可能给程序带来麻烦,同时也希望这个方法是“私有”的,是不能被扩展的,我们可以使用final关键字来修饰不需要被覆盖或者被扩展的方法。
|
程序调试结果:
Fatal error: Cannot override final method Person::say() in D:\PhpServer\wamp\www\phptest\parent.php on line 19
最新文章
- C++中的 :: 用法
- 一款漂亮实用的Android开源日期控件timessquare
- 小白安装linux(虚拟机)red hat enterprise linux 6
- SQL between查询 范围查询
- Scala应用函数
- C++ 11 笔记 (二) : for循环
- 用 CALayer 定制下载进度条控件
- C# winform平台下使用spread控件导出excel表格
- flowable设计器插件安装
- 恢复oracle中误删除drop掉的表 闪回的方法
- popstate事件在低版本webkit中的调用
- MATLAB中a(:)和."; ' ";,"; ' ";
- python基础1-转自金角大王
- CentOS 7下安装Python3.6
- poj-2406(kmp水题)
- CF 1051F
- java学习--第50天讲到jquery
- 待选框、目标框select项目左右移动
- jquery 之ajax,get,post异步请求简单代码模版
- python科学计算模块NumPy
热门文章
- mfc release 版本 内存不足 的解决方法
- MVC+EasyUI 菜单导航的实现
- eclipse项目debug方法
- 25+ Useful Selenium Web driver Code Snippets For GUI Testing Automation
- JavaScript 命名规则
- .Net中的泛型(where T : class的含义)
- 再看 AspriseOCR - OCR应用开发 -20151124
- phoenix 索引修复-基本流程
- 树莓派摄像头模块转成H264编码通过RTMP实现Html输出
- CRLF和LF