1. interface DoStuff2 {  2. float getRange(int low, int high); }  3.  4. interface DoMore {  5. float getAvg(int a, int b, int c); }  6.  7. abstract class DoAbstract implements DoStuff2, DoMore { }  8.  9. class DoStuff implements DoStuff2 {  10. public

题目

1. interface DoStuff2 {  2. float getRange(int low, int high); }  3.  4. interface DoMore {  5. float getAvg(int a, int b, int c); }  6.  7. abstract class DoAbstract implements DoStuff2, DoMore { }  8.  9. class DoStuff implements DoStuff2 {  10. public float getRange(int x, int y) { return 3.14f; } }  11.  12. interface DoAll extends DoMore {  13. float getAvg(int a, int b, int c, int d); }  What is the result?() 

  • A、 The file will compile without error.
  • B、 Compilation fails. Only line 7 contains an error.
  • C、 Compilation fails. Only line 12 contains an error.
  • D、 Compilation fails. Only line 13 contains an error.
  • E、 Compilation fails. Only lines 7 and 12 contain errors.
  • F、 Compilation fails. Only lines 7 and 13 contain errors.
  • G、 Compilation fails. Lines 7, 12, and 13 contain errors.

相似考题
更多“1. interface DoStuff2 {  2. float getRange(int low, int high); }  3.  4. interface DoMore {  5. float getAvg(int a, int b, int c); }  6.  7. abstract class DoAbstract implements DoStuff2, DoMore { }  8.  9. class DoStuff implements DoStuff2 {  10. public ”相关问题
  • 第1题:

    类Test定义如下,将下列哪个方法插入③行处是不合法的( )?

    ① public class Test{

    ② public float Method(float a,float B) { }

    ③ ______

    ④ }

    A.public float Method(float a,float b,float C) { }

    B.public float Method(float c,float d){ }

    C.public int Method(int a,int B) { }private float Method(int a,int b,int C) { }

    D.private float Method(int a,int b,int C) { }


    正确答案:B
    解析:本题主要考查方法重载,方法的重载是指多个方法可以享有相同的名字,但参数的数量或类型必须不相同(采用不同的形式参数列表),选项B不符合方法重载的要求。

  • 第2题:

    1. class A {  2. public int getNumber(int a) {  3.     return a + 1;  4. }  5. }  6.    7. class B extends A {  8. public int getNumber (int a) {  9. return a + 2  10. }  11.    12. public static void main (String args[])  {  13. A a = new B();  14. System.out.printIn(a.getNumber(0));  15.    } 16. }     What is the result?()  

    • A、 Compilation succeeds and 1 is printed.
    • B、 Compilation succeeds and 2 is printed.
    • C、 An error at line 8 causes compilation to fail.
    • D、 An error at line 13 causes compilation to fail.
    • E、 An error at line 14 causes compilation to fail.

    正确答案:B

  • 第3题:

    interface DeclareStuff{  public static final int EASY = 3;  void doStuff(int t); }  public class TestDeclare implements DeclareStuff {  public static void main(String [] args) {  int x=5;  new TestDeclare().doStuff(++x);  }  void doStuff(int s) {  s += EASY + ++s;  System.out.println(”s “ + s);  }  }  What is the result?() 

    • A、 s 14
    • B、 s 16
    • C、 s 10
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:D

  • 第4题:

    现有:   1. class Synapse {    2.    protected int gap() { return 7; }    3. }   4.     5. class Creb extends Synapse {    6.   // insert code here   7. }    分别插入到第 6 行,哪三行可以编译?()

    • A、 int gap() { return 7; }
    • B、 public int gap() { return 7; }
    • C、 private int gap(int x) { return 7; }
    • D、 protected Creb gap() { return this; }
    • E、 public int gap() { return Integer.getInteger ("42"); }

    正确答案:B,C,E

  • 第5题:

    1. interface foo {  2. int k = 0;  3. } 4.    5. public class test implements Foo (  6. public static void main(String args[]) (  7. int i;  8. Test test = new test ();  9. i= test.k;  10.i= Test.k;  11.i= Foo.k;  12.)  13.)  14.        What is the result?()  

    • A、 Compilation succeeds.
    • B、 An error at line 2 causes compilation to fail.
    • C、 An error at line 9 causes compilation to fail.
    • D、 An error at line 10 causes compilation to fail.
    • E、 An error at line 11 causes compilation to fail.

    正确答案:A

  • 第6题:

    public class MethodOver  {  public void setVar (int a, int b, float c)  {  }  }   Which two overload the setVar method?()  

    • A、 Private void setVar (int a, float c, int b)  { }
    • B、 Protected void setVar (int a, int b, float c) { }
    • C、 Public int setVar (int a, float c, int b) (return a;)
    • D、 Public int setVar (int a, int b, float c) (return a;)
    • E、 Protected float setVar (int a, int b, float c) (return c;)

    正确答案:A,C

  • 第7题:

    1. public class A {  2. public String doit(int x, int y) {  3. return “a”;  4. }  5.  6. public String doit(int... vals) {  7. return “b”;  8. } 9. }  Given:  25. A a=new A();  26. System.out.println(a.doit(4, 5));  What is the result?() 

    • A、 Line 26 prints “a” to System.out.
    • B、 Line 26 prints „b” to System.out.
    • C、 An exception is thrown at line 26 at runtime.
    • D、 Compilation of class A will fail due to an error in line 6.

    正确答案:A

  • 第8题:

    现有:   1. interface Altitude {   2.   //insert code here  3. }    和4个声明:  int HIGH = 7;   public int HIGH = 7;   abstract int HIGH = 7;   interface int HIGH = 7;    分别插入到第2行,有多少行可以编译?()  

    • A、 0
    • B、 1
    • C、 2
    • D、 3
    • E、 4

    正确答案:C

  • 第9题:

    多选题
    1. class SuperFoo {  2. SuperFoo doStuff(int x) {  3. return new SuperFoo(); 4. }  5. }  6.  7. class Foo extends SuperFoo {  8. //insert code here  9. }   下面哪三项分别插入到第8行,可以编译?()
    A

    int doStuff() { return 42; }

    B

    int doStuff(int x) { return 42; }

    C

    Foo doStuff(int x) { return new Foo(); }

    D

    SuperFoo doStuff(int x) { return new Foo(); }


    正确答案: B,A
    解析: 暂无解析

  • 第10题:

    多选题
    Given the following interface definition, which definitions are valid?()   interface I {   void setValue(int val);   int getValue();   }    DEFINITION a:   (a) class a extends I {  int value;   void setValue(int val) { value = val;  }   int getValue() {  return value;  }   }   DEFINITION b:   (b) interface b extends I {   void increment();   }   DEFINITION c:   (c) abstract class c implements I {   int getValue() {  return 0;  }  abstract void increment();   }   DEFINITION d:   (d) interface d implements I {  void increment();  }   DEFINITION e:   (e) class e implements I {  int value;   public void setValue(int val) { value = val; }  }
    A

    Definition a.

    B

    Definition b.

    C

    Definition c.

    D

    Definition d.

    E

    Definition e.


    正确答案: A,B
    解析: 暂无解析

  • 第11题:

    多选题
    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()
    A

    public class Circle implements Shape { private int radius; }

    B

    public abstract class Circle extends Shape { private int radius; }

    C

    public class Circle extends Shape { private int radius; public void draw(); }

    D

    public abstract class Circle implements Shape { private int radius; public void draw(); }

    E

    public class Circle extends Shape { private int radius;public void draw() {/* code here */} }

    F

    public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }


    正确答案: B,F
    解析: 暂无解析

  • 第12题:

    多选题
    Given:  1. public class Method Over {  2. public void set Var (int a, int b, float c) {  3. }  4. }   Which two overload the set Var method()?
    A

    private void set Var(int a, float c, int b) {}

    B

    protected void set Var(int a, int b, float c) {}

    C

    public int set Var(int a, float c, int b) {return a:}

    D

    public int set Var(int a, int b, float c) {return a:}

    E

    protected float set Var(int a, int b, float c) {return c:}


    正确答案: A,C
    解析: 暂无解析

  • 第13题:

    有一个接口定义如下,下列选项中实现了该接口并且不是抽象的是 interface A { int method1(int i); int method2(int j); }

    A.class B implements A { int method 1(){} int method 2(){} }

    B.class B { int method 1(int i){} int method 2(int j){} }

    C.class B implements A { int method 1(int i){} int method 2(int j){} }

    D.class B extends A { int method 2(int j){} int method 1(int j){} }


    正确答案:C
    解析:本题考查在Java中接口的实现。接口是一种只含有抽象方法或变量的特殊的抽象类。在类的声明中用implements子句来表示一个类使用某个接口。选项A在方法内没有参数值;选项B只是定义了一个类,并没有实现与A的接口:选项C中使用关键字implements实现了该接口,这里接口中的方法并没有使用abstract修饰,所以不是抽象的;选项D中extends是用宋继承父类的,而A并不是一个类,不能用extends。

  • 第14题:

    1. public class Target {  2. private int i = 0;  3. public int addOne() {  4. return ++i;  5. }  6. }  And:  1. public class Client {  2. public static void main(String[] args) {  3. System.out.println(new Target().addOne());  4. }  5. }  Which change can you make to Target without affecting Client?() 

    • A、 Line 4 of class Target can be changed to return i++;
    • B、 Line 2 of class Target can be changed to private int i = 1;
    • C、 Line 3 of class Target can be changed to private int addOne() {
    • D、 Line 2 of class Target can be changed to private Integer i = 0;

    正确答案:D

  • 第15题:

    Given:  1. public class Method Over {  2. public void set Var (int a, int b, float c) {  3. }  4. }   Which two overload the set Var method()?

    • A、 private void set Var(int a, float c, int b) {}
    • B、 protected void set Var(int a, int b, float c) {}
    • C、 public int set Var(int a, float c, int b) {return a:}
    • D、 public int set Var(int a, int b, float c) {return a:}
    • E、 protected float set Var(int a, int b, float c) {return c:}

    正确答案:A,C

  • 第16题:

    Given the following interface definition, which definitions are valid?()   interface I {   void setValue(int val);   int getValue();   }    DEFINITION a:   (a) class a extends I {  int value;   void setValue(int val) { value = val;  }   int getValue() {  return value;  }   }   DEFINITION b:   (b) interface b extends I {   void increment();   }   DEFINITION c:   (c) abstract class c implements I {   int getValue() {  return 0;  }  abstract void increment();   }   DEFINITION d:   (d) interface d implements I {  void increment();  }   DEFINITION e:   (e) class e implements I {  int value;   public void setValue(int val) { value = val; }  }  

    • A、Definition a.
    • B、Definition b.
    • C、Definition c.
    • D、Definition d.
    • E、Definition e.

    正确答案:B,C

  • 第17题:

    1. class SuperFoo {  2. SuperFoo doStuff(int x) {  3. return new SuperFoo(); 4. }  5. }  6.  7. class Foo extends SuperFoo {  8. //insert code here  9. }   下面哪三项分别插入到第8行,可以编译?()

    • A、int doStuff() { return 42; }
    • B、int doStuff(int x) { return 42; }
    • C、Foo doStuff(int x) { return new Foo(); }
    • D、SuperFoo doStuff(int x) { return new Foo(); }

    正确答案:A,C,D

  • 第18题:

    现有:  1. interface Animal {  2. void eat();  3. }  4.  5. // insert code here  6.  7. public class HouseCat extends Feline {  8. public void eat() { }  9. }   和五个声明:  abstract class Feline implements Animal { }  abstract class Feline implements Animal { void eat(); }  abstract class Feline implements Animal { public void eat(); }  abstract class Feline implements Animal { public void eat() { } }  abstract class Feline implements Animal { abstract public void eat(); }  分别插入到第5行,有几个可以通过编译?() 

    • A、0
    • B、1
    • C、2
    • D、3

    正确答案:D

  • 第19题:

    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()

    • A、 public class Circle implements Shape { private int radius; }
    • B、 public abstract class Circle extends Shape { private int radius; }
    • C、 public class Circle extends Shape { private int radius; public void draw(); }
    • D、 public abstract class Circle implements Shape { private int radius; public void draw(); }
    • E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
    • F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

    正确答案:B,E

  • 第20题:

    多选题
    public class MethodOver  {  public void setVar (int a, int b, float c)  {  }  }   Which two overload the setVar method?()
    A

    Private void setVar (int a, float c, int b)  { }

    B

    Protected void setVar (int a, int b, float c) { }

    C

    Public int setVar (int a, float c, int b) (return a;)

    D

    Public int setVar (int a, int b, float c) (return a;)

    E

    Protected float setVar (int a, int b, float c) (return c;)


    正确答案: D,C
    解析: 暂无解析

  • 第21题:

    单选题
    1. public class A {  2. public String doit(int x, int y) {  3. return “a”;  4. }  5.  6. public String doit(int... vals) {  7. return “b”;  8. } 9. }  Given:  25. A a=new A();  26. System.out.println(a.doit(4, 5));  What is the result?()
    A

     Line 26 prints “a” to System.out.

    B

     Line 26 prints „b” to System.out.

    C

     An exception is thrown at line 26 at runtime.

    D

     Compilation of class A will fail due to an error in line 6.


    正确答案: C
    解析: 暂无解析

  • 第22题:

    单选题
    现有:   1. interface Altitude {   2.   //insert code here  3. }    和4个声明:  int HIGH = 7;   public int HIGH = 7;   abstract int HIGH = 7;   interface int HIGH = 7;    分别插入到第2行,有多少行可以编译?()
    A

     0

    B

     1

    C

     2

    D

     3

    E

     4


    正确答案: D
    解析: 暂无解析

  • 第23题:

    单选题
    interface DeclareStuff{  public static final int EASY = 3;  void doStuff(int t); }  public class TestDeclare implements DeclareStuff {  public static void main(String [] args) {  int x=5;  new TestDeclare().doStuff(++x);  }  void doStuff(int s) {  s += EASY + ++s;  System.out.println(”s “ + s);  }  }  What is the result?()
    A

     s 14

    B

     s 16

    C

     s 10

    D

     Compilation fails.

    E

     An exception is thrown at runtime.


    正确答案: E
    解析: 暂无解析