JAVA程序设计第六章

一. 填空题(共7题,70分)

1. (填空题)接口中是否能声明变量吗?回答是或者否______。

(1) 否

2. (填空题)接口中是否能定义非抽象方法吗?回答是或者否_______。

(1)

3. (填空题)可以把实现某一接口的类创建的对象的引用赋给该接口声明的_____变量中。那么该______变量就可以调用被类实现的接口中的方法。

(1)

接口

(2)

接口

4. (填空题)接口中的常量可以不指定初值吗?回答可以或者不可以________。

(1)

不可以

5. (填空题)

可以在接口中只声明常量,不声明抽象方法吗?回答可以或者不可以________。

(1)

可以

6. (填空题)

请说出E类中【代码1】,【代码2】的输出结果_________,__________。

interface A {

   double f(double x,double y); 

}

class B implements A {

  public double f(double x,double y) {

     return x*y;

  }

  int g(int a,int b) {

     return a+b;

  }

}

public class E {

public static void main(String args[]) {

      A a = new B();

      System.out.println(a.f(3,5)); //【代码1】

      B b = (B)a;

      System.out.println(b.g(3,5)); //【代码2】

  }

}

(1) 15.0

(2) 8

7. (填空题)

请说出E类中【代码1】,【代码2】的输出结果_________,__________。

interface Com {

   int add(int a,int b);

}

abstract class A {

   abstract int add(int a,int b);

}

class B extends A implements Com{

   public int add(int a,int b) {

      return a+b;

   }

}

public class E {

public static void main(String args[]) {

     B b = new B();

     Com com = b;

     System.out.println(com.add(12,6)); //【代码1】

     A a = b;

     System.out.println(a.add(10,5));   //【代码2】

  }

}

(1) 18

(2) 15

二. 单选题(共2题,20分)

8. (单选题)

下列哪个叙述是正确的?

  • A. 一个类最多可以实现两个接口。
  • B. 如果一个抽象类实现某个接口,那么它必须要重写接口中的全部方法。
  • C. 如果一个非抽象类实现某个接口,那么它可以只重写接口中的部分方法。
  • D. 允许接口中只有一个抽象方法。

D :允许接口中只有一个抽象方法。; 

9. (单选题)

将下列(A,B,C,D)哪个代码替换下列程序中的【代码】不会导致编译错误。

interface Com {

    int M = 200;

    int f();

}

class ImpCom implements Com {

   【代码】

}

  • A. public int f(){return 100+M;}
  • B. int f(){return 100;}
  • C. public double f(){return 2.6;}
  • D. public abstract int f();

A :public int f(){return 100+M;}; 

三. 多选题(共1题,10分)

10. (多选题)

下列接口中标注的(A,B,C,D)中,哪两个是错误的?

interface Takecare {

    protected void speakHello();          //A

    public abstract static void cry();        //B

    int f();                            //C

    abstract float g();                   //D

}

  • A.  protected void speakHello();  
  • B. public abstract static void cry();   
  • C. int f();  
  • D. abstract float g();  

AB

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值