为了账号安全,请及时绑定邮箱和手机立即绑定

各位大神,我这是哪错了?

各位大神,我这是哪错了?

PHP
caidick 2016-07-22 11:43:15
<?phpclass Human{ public $name; public $height; public $weight; private $age=40;//只能在类的内部被访问 public function eat($foot){ echo $this->name."'s eating ".$foot."<br>"; }}class NbaPlay extends Human{ public $team = "Bull"; public $playerNumber='23'; function __construct($name,$height,$weight,$team,$playerNumber){ echo "in nabplay"."<br>"; $this->name = $name;//$this是php里的伪变量表示对象自身。可以通过$this->的方式访问对象的属性和方法。 $this->height = $height; $this->weight = $weight; $this->team = $team; $this->playerNumber = $playerNumber; } function __destruct(){ echo "lllll".$this->team."<br>"; } public function run(){ echo "Running\n"; } public function jump(){ echo "Jumping\n"; } public function dribble(){ echo "Dribbleing\n"; } public function shoot(){ echo "Shooting\n"; } public function dunk(){ echo "Dunking\n"; } public function pass(){ echo "Passing\n"; } public function getAge(){ echo $this->name."年龄是".$this->age."<br>"; } }$jordan = new NbaPlay('jordan','180cm','160kg','lcl','24');$jordan->getAge();echo "<br>"; 
查看完整描述

2 回答

?
坚强

TA贡献5条经验 获得超16个赞

将Human类中的private $age 改成 public $age

查看完整回答
反对 回复 2016-07-22
?
qq_大寒_2

TA贡献173条经验 获得超185个赞

private $age=40;//只能在类的内部被访问 

public $age-40;

查看完整回答
反对 回复 2016-07-22
  • 2 回答
  • 0 关注
  • 1379 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信