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.

26 lines
641 B

3 years ago
3 years ago
3 years ago
  1. <?php
  2. /**
  3. * 抽象类就是类中留出部分未定义的属性或方法
  4. * 留给继承的子类去继续填充定义
  5. */
  6. //这是一个抽象类
  7. abstract class animal
  8. {
  9. public $eyes = 2;
  10. public $foots = 4;
  11. abstract public function eat(); //抽象方法
  12. }
  13. class dog extends animal //继承抽象类
  14. {
  15. public function eat() //子类必须实现抽象类中的抽象方法
  16. {
  17. echo "狗吃骨头".'<br>';
  18. }
  19. }
  20. $adog = new dog();
  21. $adog -> eat();
  22. //注意:抽象类不能被实例化,已经要被子类继承
  23. ?>