1700458950
public class HummerH2Model extends HummerModel{
1700458951
1700458952
protected void alarm(){
1700458953
1700458954
System.out.println(“悍马H2鸣笛……”);
1700458955
1700458956
}
1700458957
1700458958
protected void engineBoom(){
1700458959
1700458960
System.out.println(“悍马H2引擎声音是这样在……”);
1700458961
1700458962
}
1700458963
1700458964
protected void start(){
1700458965
1700458966
System.out.println(“悍马H2发动……”);
1700458967
1700458968
}
1700458969
1700458970
protected void stop(){
1700458971
1700458972
System.out.println(“悍马H2停车……”);
1700458973
1700458974
}
1700458975
1700458976
//默认没有喇叭的
1700458977
1700458978
protected boolean isAlarm(){
1700458979
1700458980
return false;
1700458981
1700458982
}
1700458983
1700458984
}
1700458985
1700458986
H2型号的悍马设置isAlarm()的返回值为false,也就是关闭了喇叭功能。场景类代码如代码清单10-12所示。
1700458987
1700458988
代码清单10-12 扩展后的场景类
1700458989
1700458990
public class Client{
1700458991
1700458992
public static void main(String[]args)throws IOException{
1700458993
1700458994
System.out.println(”––-H1型号悍马––—”);
1700458995
1700458996
System.out.println(“H1型号的悍马是否需要喇叭声响?0-不需要1-需要”);
1700458997
1700458998
String type=(new BufferedReader(new InputStreamReader(System.in))).readLine();
1700458999
[
上一页 ]
[ :1.70045895e+09 ]
[
下一页 ]