<?php /** * Created by PhpStorm. * User: siyu.wang * Date: 2017/9/26 * Time: 14:36 */ /** * final 修饰的方法不可以被重写 * 不可以修饰属性 */ class person{ public $age = 23; final public function getAge(){ return $this->age; } } class stu extends person{ // public function getAge(){ // return $this->age; // } } $n = new stu(); echo $n->getAge();
final
最新推荐文章于 2025-06-27 21:26:16 发布
本文通过一个简单的PHP代码示例介绍了final关键字的作用:使用final修饰的方法不可被子类重写。示例中定义了一个名为person的基础类,其中包含一个final修饰的getAge()方法,随后通过继承创建了一个新的类stu并尝试调用该方法。
797

被折叠的 条评论
为什么被折叠?



