当前位置:Gxlcms > PHP教程 > php5中抽象类的小例子

php5中抽象类的小例子

时间:2021-07-01 10:21:17 帮助过:2人阅读

  1. /**

  2. * 定义与使用php抽象类
  3. * edit: bbs.it-home.org
  4. */
  5. abstract class Number {
  6. private $value;
  7. abstract public function value();
  8. public function reset() {
  9. $this->value = NULL;
  10. }
  11. }

  12. class Integer extends Number {

  13. private $value;
  14. public function value() {
  15. return (int)$this->value;
  16. }
  17. }

  18. $num = new Integer; /* Okay */

  19. $num2 = new Number; /* This will fail */
  20. ?>

人气教程排行