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

<?php
class Car {
    public $speed = 0; //汽车的起始速度是0
    
    public function speedUp() {
        $this->speed += 10;
        return $this->speed;
    }
}
//定义继承于Car的Truck类
class Truck extends car{
    
    public function speedUp(){
        
        $this->speed=parent::speedUp()+40;
    }
}

$car = new Truck();
$car->speedUp();
echo $car->speed;

正在回答

举报

0/150
提交
取消
PHP进阶篇
  • 参与学习       181982    人
  • 解答问题       2668    个

轻松学习PHP中级课程,进行全面了解,用PHP快速开发网站程序

进入课程
微信客服

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

帮助反馈 APP下载

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

公众号

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