编写一个父类Person(人),包含name,xb(性别)两个变量和一个构造器,在构造器中完成姓名性别的初始化,编写一个子类student继承自Person,包含xh(学号)变量和构造器,并在子类中定义一个方法,用来传输全部学生信息。{代码如图,运行一直错误,求大神指正,错误如下图}
header("Content-type: text/html; charset=utf-8");
class person{
public $name;
public $xb;
function _construct($xm,$sex){
$this->name=$xm;
$this->xb=$sex;
}
}
class student extends person{
var $xh;
function _construct($xm,$sex,$id){
$this->xh=$id;
parent::_construct($xm,$sex);
}
function getInfo(){
echo '姓名:'.$this->name.'<br>';
echo '性别:'.$this->xb.'<br>';
echo '学号:'.$this->xh.'<br>';
}
}
$stu1=new student;
$stu1->_construct('张三','男','20011020305');
$stu1->getInfo();
class person{
public $name;
public $xb;
function _construct($xm,$sex){
$this->name=$xm;
$this->xb=$sex;
}
}
class student extends person{
var $xh;
function _construct($xm,$sex,$id){
$this->xh=$id;
parent::_construct($xm,$sex);
}
function getInfo(){
echo '姓名:'.$this->name.'<br>';
echo '性别:'.$this->xb.'<br>';
echo '学号:'.$this->xh.'<br>';
}
}
$stu1=new student;
$stu1->_construct('张三','男','20011020305');
$stu1->getInfo();
温馨提示:答案为网友推荐,仅供参考