final关键字的应用
2016-07-02 18:17
232 查看
这个关键字只能用来定义类和定义方法, 不能使用final这个关键字来定义成员属性,因为final是常量的意思,我们在PHP里定义常量使用的是define()函数,所以不能使用final来定义成员属性。使用final关键标记的类不能被继承;
01<?php
02final class Person
03{
04 function say()
05 {
06
07 }
08}
09
10class Student extends Person
11{
12 function say()
13 {
14
15 }
16}
17?>
会出现下面错误:
1Fatal error: Class Student may not inherit from final class (Person)
使用final关键标记的方法不能被子类覆盖,是最终版本;
01<?php
02class Person
03{
04 final function say()
05 {
06
07 }
08
09}
10
11class Student extends Person
12{
13 function say()
14 {
15
16 }
17}
18?>
会出现下面错误:
view source
?
1Fatal error: Cannot override final method Person::say()
01<?php
02final class Person
03{
04 function say()
05 {
06
07 }
08}
09
10class Student extends Person
11{
12 function say()
13 {
14
15 }
16}
17?>
会出现下面错误:
1Fatal error: Class Student may not inherit from final class (Person)
使用final关键标记的方法不能被子类覆盖,是最终版本;
01<?php
02class Person
03{
04 final function say()
05 {
06
07 }
08
09}
10
11class Student extends Person
12{
13 function say()
14 {
15
16 }
17}
18?>
会出现下面错误:
view source
?
1Fatal error: Cannot override final method Person::say()
相关文章推荐
- VS+mysql+EF搭建
- linux截图工具ksnapshot
- 最小生成树
- jadclipse插件安装
- 无线信道抗衰落技术
- 获取teechart图表控件的x轴的起始位置和右边界(即终止位置)
- Spring Security(01)——初体验
- How Far are We from Solving Pedestrian Detection?
- hdu 5656 CA Loves GCD dp
- Windows Server 2008 R2和2012中PHP连接MySQL过慢的解决方法
- 线段树练习4
- Linux上的日志系统
- 数据库优化
- Python正则表达式详解
- 微信支付
- Java-类库-Guava-EventBus
- 在unity运行的时候运行Update
- 湘潭oj_1250 Super Fast Fourier Transform
- 《OD学hadoop》第一周0626 作业二:Linux基础
- AFNetWorking(3.0)源码分析(一)——基本框架