php5中抽象类的小例子
时间:2021-07-01 10:21:17
帮助过:2人阅读
/** - * 定义与使用php抽象类
- * edit: bbs.it-home.org
- */
- abstract class Number {
- private $value;
- abstract public function value();
- public function reset() {
- $this->value = NULL;
- }
- }
class Integer extends Number { - private $value;
- public function value() {
- return (int)$this->value;
- }
- }
$num = new Integer; /* Okay */ - $num2 = new Number; /* This will fail */
- ?>
|