You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
668 B
30 lines
668 B
<?php
|
|
|
|
//使用 final 修饰的类,不能被继承;
|
|
final class plant
|
|
{
|
|
public $tall;
|
|
}
|
|
|
|
class tree extends plant //应该会报错 Class tree may not inherit from final class (plant)
|
|
{
|
|
public $color;
|
|
}
|
|
|
|
|
|
//类中使用 final 修饰的成员方法,在子类中不能覆盖(重写)该方法。
|
|
class animal
|
|
{
|
|
final public function eat(){
|
|
echo "animal eat".'<br>';
|
|
}
|
|
}
|
|
|
|
class dog extends animal
|
|
{
|
|
public function eat() //应该会报错 Cannot override final method animal::eat()
|
|
{
|
|
echo "dog eat bone".'<br>';
|
|
}
|
|
}
|
|
?>
|