首页 > php面向对象 > PHP 面向对象 final类与final方法

PHP 面向对象 final类与final方法

Fatal error: Class SuperMath may not inherit from final class (Math) in E:PHPProjects est.php on line 14

<?php
//声明一个final类Math
class Math {
    public static $pi = 3.14;
    public function __toString() {
        return "这是Math类。";
    }
    public final function max($a, $b) {
        return $a > $b ? $a : $b;
    }
}
//声明类SuperMath 继承自 Math类
class SuperMath extends Math {
    public final function max($a, $b) {
    }
}
//执行会出错,final方法不能被重写。
 < ? php
//声明一个final类Math
final class Math {
    public static $pi = 3.14;
    public function __toString() {
        return "这是Math类。";
    }
}
$math = new Math();
echo $math;
//声明类SuperMath 继承自 Math类
class SuperMath extends Math {
}

//执行会出错,final类不能被继承。

Fatalerror : Class SuperMathmaynotinheritfromfinal class (Math) inE:

PHPProjectsest . phponline16


教程网址:http://www.phprm.com/mxdx/fs5163.html

欢迎收藏∩_∩但请保留本文链接。

标签:php面向对象 final类 final方法

相关文章

发表留言