abstract class Animal//有抽象方法必然是抽象类 { protected $name; public abstract function cry(); } class Cat extends Animal { public function cry() { echo "喵喵叫<br/>"; } } class Dog extends Animal { public function cry() { echo "旺旺叫<br/>"; } } $an = new Cat(); $an->cry(); $an = new Dog(); $an->cry();
输出:
喵喵叫
旺旺叫