抽象方法问题

时间:2012-06-24 13:11:33

标签: php-5.3

<?php
abstract class a{
    abstract protected function test();
    function threeDots(){
        return '...';

    }
}
class b extends a{

     protected function test(){
        echo $this->threeDots();
    }
}
$obj = new a();


   $obj->test();
?>

上面的代码给出错误......但是不能理解为什么?

1 个答案:

答案 0 :(得分:0)

此行错误:

$obj = new a();

因为您无法创建抽象类的实例。 也许,你想写:$obj = new b();