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.

29 lines
668 B

3 years ago
  1. <?php
  2. //使用 final 修饰的类,不能被继承;
  3. final class plant
  4. {
  5. public $tall;
  6. }
  7. class tree extends plant //应该会报错 Class tree may not inherit from final class (plant)
  8. {
  9. public $color;
  10. }
  11. //类中使用 final 修饰的成员方法,在子类中不能覆盖(重写)该方法。
  12. class animal
  13. {
  14. final public function eat(){
  15. echo "animal eat".'<br>';
  16. }
  17. }
  18. class dog extends animal
  19. {
  20. public function eat() //应该会报错 Cannot override final method animal::eat()
  21. {
  22. echo "dog eat bone".'<br>';
  23. }
  24. }
  25. ?>