刷题刷出新高度,偷偷领先!偷偷领先!偷偷领先! 关注我们,悄悄成为最优秀的自己!
简答题
请阅读上述说明和Java代码,完成填空和简答题。
使用微信搜索喵呜刷题,轻松应对考试!
答案:
(2)light.on()
(3)light.off()
(4)onCommands[slot]
(5)offCommands[slot]
(6)onCommands[slot].execute()
(7)offCommands[slot].execute()
解析:
(1)Command是一个接口,定义了一个execute方法,用于执行命令。
(2)在LightOnCommand类的execute方法中,应调用Light对象的on方法,以执行开灯命令。
(3)在LightOffCommand类的execute方法中,应调用Light对象的off方法,以执行关灯命令。
(4)在RemoteControl类的setCommand方法中,将传入的onCommand对象赋值给onCommands数组的指定位置,即onCommands[slot] = onCommand。
(5)同样,在RemoteControl类的setCommand方法中,将传入的offCommand对象赋值给offCommands数组的指定位置,即offCommands[slot] = offCommand。
(6)在RemoteControl类的onButtonWasPushed方法中,调用onCommands数组中对应位置的execute方法,即onCommands[slot].execute()。
(7)在RemoteControl类的offButtonWasPushed方法中,调用offCommands数组中对应位置的execute方法,即offCommands[slot].execute()。
创作类型:
原创
版权声明:本站点所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明文章出处。 让学习像火箭一样快速,微信扫码,获取考试解析、体验刷题服务,开启你的学习加速器!



