时间:2021-07-01 10:21:17 帮助过:19人阅读
Example #1 Final 方法示例
class BaseClass { public function test(){ echo "BaseClass::test() called<br>"; } final public function moreTesting(){ echo "BaseClass::moreTesting() called<br>"; } } class ChildClass extends BaseClass { public function moreTesting(){ echo "BaseClass::moreTeing called<br>"; } }
Example #2 Final 类示例
final class BaseClass{ public function test(){ echo "BaseClass::test() called\n"; } //这里无论你是否将方法声明为final,都没有关系 final public function moreTesting(){ echo "BaseClass::moreTesting() called\n"; } } class ChildClass extends BaseClass{} //产生Fatal Error:Class ChildClass may not inherit from final class (BaseClass)
Note: 属性不能被定义为 final,只有类和方法才能被定义为 final。