PhP面向对象编程练习题

发布网友

我来回答

3个回答

热心网友

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();

热心网友

麻烦你写代码的时候用半角输入,你这代码的符号全部都是全角符号。

热心网友

construct函数前的两个下划线之间不应该有空格。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com