//构造方法继承
<?php
class Student{
//私有的成员属性
private $name;
private $age;
//构造方法
public function __construct($name,$age){
$this->name = $name;
$this->age = $age;
}
//公共的显示方法
public function ShowInfo(){
echo "{$this->name}的年龄是{$this->age}";
}
}
//定义一个中学生类并继承学生类
class MiddleStudent extends Student{
}
$obj = new MiddleStudent('jon',20);
$obj->ShowInfo();//调用子类继承父类的方法