-->
当前位置:首页 > 题库 > 正文内容

函数题:坦克与火箭

Luz3年前 (2022-10-27)题库926
已有类Car、Plane。请创建接口Weapon以及类Tank和Fighter。
接口Weapon中定义了无参数和返回值的方法shoot。
类Tank和Fighter分别继承Car和Plane,并且都实现了接口weapon。
请在类Tank和Fighter中分别实现接口weapon中的方法Shoot,Tank类中的shoot方法能够打印“发射大炮”,Fighter类中的shoot方法能够打印“发射火箭”。


### 裁判测试程序样例:
java
在这里给出函数被调用进行测试的例子。例如:
class Car{
public void move() {
System.out.println("running");
}
}
class Plane{
public void move() {
System.out.println("flying");
}
}

/* 请在这里填写答案 */



public class Main{
public static void main(String argv[]){
Tank tank = new Tank();
Fighter fighter = new Fighter();
tank.move();
tank.shoot();
fighter.move();
fighter.shoot();
Weapon tank2 = new Tank();
Weapon fighter2= new Fighter();
tank2.shoot();
fighter2.shoot();
}
}


### 输出样例:无输入
in



### 输出样例:

在这里给出相应的输出。例如:

out
running
发射大炮
flying
发射火箭
发射大炮
发射火箭








答案:若无答案欢迎评论

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。