<?php
//******使用关键字abstract声明该类为抽象类*****
abstract class Person{
protected $name;
protected $age;
function __construct($name="",$age=18){
$this->name=$name;
$this->age=$age;
}
//***声明抽象类中的抽象方法****
//***抽象方法不必声明具体的行为***
abstract function getname();
abstract function getage();
function greeting(){
echo "hello,world";
}
}
//***抽象类不能被直接实例化,只能通过子类继承***
class newPerson1 extends Person{
//***子类必须对抽象类中的全部抽象方法进行实现处理***
function getname(){
echo "the name is ".$this->name."<br/>";
}
function getage(){
echo "the age is ".$this->age."<br/>";
}
}
$tom = new newPerson1("tom",20);
$tom->getname();
$tom->getage();
$tom->greeting();
?>
转载于:https://my.oschina.net/dongdong11019/blog/493145