1700458470
1700458471
//先发动汽车
1700458472
1700458473
this.start();
1700458474
1700458475
//引擎开始轰鸣
1700458476
1700458477
this.engineBoom();
1700458478
1700458479
//然后就开始跑了,跑的过程中遇到一条狗挡路,就按喇叭
1700458480
1700458481
this.alarm();
1700458482
1700458483
//到达目的地就停车
1700458484
1700458485
this.stop();
1700458486
1700458487
}
1700458488
1700458489
}
1700458490
1700458491
大家注意看run()方法,这是一个汇总的方法,一个模型生产成功了,总要拿给客户检测吧,怎么检测,“是骡子是马,拉出去溜溜”,这就是一种检验方法,让它跑起来!通过run()这样的方法,把模型的所有功能都测试到了。
1700458492
1700458493
H2型号悍马如代码清单10-3所示。
1700458494
1700458495
代码清单10-3 H2型号悍马模型
1700458496
1700458497
public class HummerH2Model extends HummerModel{
1700458498
1700458499
//H2型号的悍马车鸣笛
1700458500
1700458501
public void alarm(){
1700458502
1700458503
System.out.println(“悍马H2鸣笛……”);
1700458504
1700458505
}
1700458506
1700458507
//引擎轰鸣声
1700458508
1700458509
public void engineBoom(){
1700458510
1700458511
System.out.println(“悍马H2引擎声音是这样在……”);
1700458512
1700458513
}
1700458514
1700458515
//汽车发动
1700458516
1700458517
public void start(){
1700458518
1700458519
System.out.println(“悍马H2发动……”);
[
上一页 ]
[ :1.70045847e+09 ]
[
下一页 ]