php类的简单的继承问题
<?phpclassstudent{private$name;function__construct($name){$this->name=$name;}publicfu...
<?php
class student
{
private $name;
function __construct($name)
{
$this->name=$name;
}
public function getName()
{
return $this->name;
}
}
class man extends student
{
private $sex;
function __construct($name,$sex)
{
parent::__construct($name);
$this->$sex=$sex;
}
public function getName()
{
echo parent::getName();
echo $this->sex;
}
}
$s = new man("xiaoming",'woman');
$s->getName();
为什么最后不能输出xiaoming 和 woman 只能输出xiaoming 展开
class student
{
private $name;
function __construct($name)
{
$this->name=$name;
}
public function getName()
{
return $this->name;
}
}
class man extends student
{
private $sex;
function __construct($name,$sex)
{
parent::__construct($name);
$this->$sex=$sex;
}
public function getName()
{
echo parent::getName();
echo $this->sex;
}
}
$s = new man("xiaoming",'woman');
$s->getName();
为什么最后不能输出xiaoming 和 woman 只能输出xiaoming 展开
1个回答
展开全部
换下位置就可以了
class man extends student
{
private $sex;
function __construct($name,$sex)
{
$this->sex=$sex;
parent::__construct($name);
}
public function getName()
{
echo parent::getName();
echo $this->sex;
}
}
$s = new man("xiaoming",'woman');
$s->getName();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询