PHP的final关键字

一 代码

<?php
	final class MyClass{								//final类MyClass
		function  __construct(){						//构造方法
			//...
		}
	}
	class ChildClass extends MyClass{					//创建MyClass的子类ChildClass
		static function exam(){						//子类中的方法
			//...
		}
	}
	$childClass = new ChildClass();
?>

 

二 运行结果
Fatal error: Class ChildClass may not inherit from final class (MyClass) in  D:\AppServ\www\test\20\13\index.php on line  11

猜你喜欢

转载自cakin24.iteye.com/blog/2377404