我试图让我清楚地了解抽象方法,所以我编写了这段代码并对其进行了测试。但是当我运行它时出现以下错误:
Fatal error: Class Book contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Book::ClassName) in C:\AppServ\www\index2.php on line 5
那么问题出在哪里,为什么?
<?php
class Book
{
abstract public function ClassName();
}
class firstBook extends Book{
public function ClassName()
{
echo "Called form class firstBook";
}
}
class secondBook extends Book{
public function ClassName()
{
echo "Called from class secondBook";
}
}
$o = new firstBook();
$o2 = new secondBook();
$o->Classname();
$o2->Classname();
?>