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.
27 lines
641 B
27 lines
641 B
<?php
|
|
/**
|
|
* 抽象类就是类中留出部分未定义的属性或方法
|
|
* 留给继承的子类去继续填充定义
|
|
*/
|
|
|
|
//这是一个抽象类
|
|
abstract class animal
|
|
{
|
|
public $eyes = 2;
|
|
public $foots = 4;
|
|
abstract public function eat(); //抽象方法
|
|
}
|
|
|
|
class dog extends animal //继承抽象类
|
|
{
|
|
public function eat() //子类必须实现抽象类中的抽象方法
|
|
{
|
|
echo "狗吃骨头".'<br>';
|
|
}
|
|
}
|
|
|
|
$adog = new dog();
|
|
$adog -> eat();
|
|
|
|
//注意:抽象类不能被实例化,已经要被子类继承
|
|
?>
|