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

小明的方法为什么不能覆盖父类?


<?php

header("Content-type: text/html; charset=utf-8");


class SportObject

{

public $name;

public $age;

public $weight;

public $sex;

function __construct($name,$age,$weight,$sex)

{

$this->name=$name;

$this->age=$age;

        $this->weight=$weight;

$this->sex=$sex;

}

public function showme(){

echo '这个应该不显示';


}

}


class basketball extends SportObject

{

function __construct($name,$height)

{

$this->name=$name;

$this->height=$height;

}

}

  function showme(){

if ($this->height>=175) {

return $this->name.",符合打篮球";

} else{

return $this->name.",不符合";

}

}



class weightlift extends SportObject

{

function showme(){

if ($this->weight<85) {

return $this->name.",符合举重";

} else {

return $this->name.",不符合";

}

}

}


$ming = new basketball('小明','160');

echo $ming->showme();

$fang = new weightlift('小方','10','100','男');

echo $fang->showme();

?>


正在回答

举报

0/150
提交
取消

小明的方法为什么不能覆盖父类?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号