最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP 面向对象 final类与final方法
时间:2010-05-06 编辑:简简单单 来源:一聚教程网
Fatal error: Class SuperMath may not inherit from final class (Math) in E:PHPProjects est.php教程 on line 14
//声明一个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方法不能被重写。
?>
//声明一个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类不能被继承。
?>
Fatal error: Class SuperMath may not inherit from final class (Math) in E:PHPProjects est.php on line 16
相关文章
- PHP面向对象开发之类的常用关键字 11-29
- PHP面向对象开发之类中接口的应用(interface、implements) 11-29
- php面向对象中子类中重载父类详解 10-24
- php面向对象抽象方法和抽象类 __call 克隆对象详细教程 03-16
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31