多选题Given: Which four code fragments, inserted independently at line 7, will compile?()Apublic void m1() { }Bprotected void m1() { }Cprivate void m1() { }Dvoid m2() { }Epublic void m2() { }Fprotected void m2() { }

题目
多选题
Given: Which four code fragments, inserted independently at line 7, will compile?()
A

public void m1() { }

B

protected void m1() { }

C

private void m1() { }

D

void m2() { }

E

public void m2() { }

F

protected void m2() { }

参考答案和解析
正确答案: F,A
解析: 暂无解析
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

若在类A中有一个无形式参数且无返回值的方法m1(),而且在调用这个方法时可以使用类名称而不是对象名称,那么声明这个方法的形式为( )。

A.static void m1 ()

B.public void m1 ()

C.final void m1 ()

D.abstract void m1;


正确答案:A
解析:在选项A中,关键字static表明方法m1是类方法,在调用这种方法时可以使用类名。在选项B中,关键字public只是说明方法m1是公有的实例方法。在选项C中,关键字final说明方法m1是最终方法,不允许被任何子类中的方法覆盖。在选项D中,关键字abstract说明方法 m1是抽象方法,它的实现过程只能在子类中定义。

第2题:

public class ExceptionTest {   class TestException extends Exception {}   public void runTest () throws TestException {}   public void test () /* Point X*/ {   runTest ();   }   }   At point X on line 4, which code can be added to make the code compile?()  

  • A、 Throws Exception.
  • B、 Catch (Exception e).
  • C、 Throws RuntimeException.
  • D、 Catch (TestException e).
  • E、 No code is necessary.

正确答案:B

第3题:

Given:Which three methods, inserted individually at line 14, will correctly complete class Two?()

A.int foo() { /* more code here */ }

B.void foo() { /* more code here */ }

C.public void foo() { /* more code here */ }

D.private void foo() { /* more code here */ }

E.protected void foo() { /* more code here */ }


参考答案:B, C, E

第4题:

Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object.   class Base {   public void print( ) {   System.out.println("base");   }   }   class Extention extends Base {   public void print( ) {   System.out.println("extension");   // insert line of implementation here   }   }   public class Q294d {   public static void main(String args[]) {   Extention ext = new Extention( );   ext.print( );   }   }   Fill in a single line of implementation.()


正确答案:super.print();

第5题:

1. class Alpha { void m1() {} }   2. class Beta extends Alpha { void m2() { } }   3. class Gamma extends Beta { }   4.   5. class GreekTest {   6. public static void main(String [] args) {   7. a Alpha [] a = {new Alpha(), new Beta(), new Gamma() };   8. for(Alpha a2 : a) {   9. a2.m1();   10. if (a2 instanceof Beta || a2 instanceof Gamma)   11. //insert code here   12. }   13. }   14. }   哪一行代码插入到第11行,将编译但是会在运行时产生异常?()  

  • A、 a2.m2();
  • B、 ((Beta)a2).m2();
  • C、 ((Alpha)a2).m2();
  • D、 ((Gamma)a2).m2();

正确答案:D

第6题:

class One {  void foo() {}  }  class Two extends One {   //insert method here  }  Which three methods, inserted individually at line 14, will correctly complete class Two?()

  • A、 int foo() { /* more code here */ }
  • B、 void foo() { /* more code here */ }
  • C、 public void foo() { /* more code here */ }
  • D、 private void foo() { /* more code here */ }
  • E、 protected void foo() { /* more code here */ }

正确答案:B,C,E

第7题:

Which two code fragments will execute the method doStuff() in a separate thread?()

  • A、 new Thread() { public void run() { doStuff(); } }
  • B、 new Thread() { public void start() { doStuff(); } }
  • C、 new Thread() { public void start() { doStuff(); } } .run();
  • D、 new Thread() { public void run() { doStuff(); } } .start();
  • E、 new Thread(new Runnable() { public void run() { doStuff(); } } ).run();
  • F、 new Thread(new Runnable() { public void run() { doStuff(); } }).start();

正确答案:D,F

第8题:

Given:Which four code fragments, inserted independently at line 7, will compile?()

A.public void m1() { }

B.protected void m1() { }

C.private void m1() { }

D.void m2() { }

E.public void m2() { }

F.protected void m2() { }

G.private void m2() { }


参考答案:A, B, E, F

第9题:

interface A { public int getValue() }  class B implements A {  public int getValue() { return 1; }  }  class C extends B {  // insert code here  }  Which three code fragments, inserted individually at line 15, make use of polymorphism?()

  • A、 public void add(C c) { c.getValue(); }
  • B、 public void add(B b) { b.getValue(); }
  • C、 public void add(A a) { a.getValue(); }
  • D、 public void add(A a, B b) { a.getValue(); }
  • E、 public void add(C c1, C c2) { c1.getValue(); }

正确答案:B,C,D

第10题:

Which three will compile and run without exception?()

  • A、private synchronized Object o;
  • B、void go(){   synchronized(){/* code here */}
  • C、public synchronized void go(){/* code here */}
  • D、private synchronized(this) void go(){/* code here */}
  • E、void go(){   synchronized(Object.class){/* code here */}
  • F、void go(){   Object o = new Object();   synchronized(o){/* code here */}

正确答案:C,E,F

更多相关问题