多选题Which three will compile and run without exception?()Aprivate synchronized Object o;Bvoid go() {synchronized() { /* code here */ }Cpublic synchronized void go() { /* code here */ }Dprivate synchronized(this) void go() { /* code here */ }Evoid go() {syn

题目
多选题
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 */ }


相似考题
更多“多选题Which three will compile and run without exception?()Aprivate synchronized Object o;Bvoid go() {synchronized() { /* code here */ }Cpublic synchronized void go() { /* code here */ }Dprivate synchronized(this) void go() { /* code here */ }Evoid go() {syn”相关问题
  • 第1题:

    下列程序的输出结果为( )。 public class Reentrant { public synchronized void a() { b(); System.out.println("here I am,in a()"); } public synchronized void b() { System.out.println("here I am,in b()"); } public static void main(String args[]) { Reentrant r=new Reentrant(); r.a(); } }

    A.here I am,in a()/here I am,in b()

    B.here I am,in b()/here I am,in a()

    C.here I am,in a()

    D.here I am,in b()


    正确答案:B
    解析:此题程序中类Reentrant定义了两个带有synchronized的方法,分别是a()和b()。在Reentrant类的main()方法中,Reentrant类的实例r调用了方法a(),在a()中调用b()。a()的执行过程中,线程的控制将请求并获得r的锁,并开始执行a()方法。由b()的定义可知,线程获得r的对象锁才能运行该方法,而此时r的锁已经由该线程获得,根据Java对象锁的可重入性,该线程将再次获得r的锁,并开始运行方法b()。

  • 第2题:

    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

  • 第3题:

    现有:  1.  class Propeller2  {  2.   pulolic static void main (String[]args)//add code here?      3.    {  new Propeller2().topGo();  }      4.  5.void topGo()  //add code here?      6.    {   middleGo();  }      7.  8.void middleGo()  //add code here?  9. {   go();  System.out.println ("late middle");  }    void go()  //add code here?      12.    {throw new Exception();  }      13.  }  为使代码通过编译,需要在哪一行加入声明throws Exception?()     

    • A、只在第11行
    • B、在第8行和第11行
    • C、在第5行、第8行和第11行
    • D、在第2行、第5行、第8行和第11行

    正确答案:D

  • 第4题:

    public class Team extends java.util.LinkedList {  public void addPlayer(Player p) {  add(p);  }  public void compete(Team opponent) { /* more code here */ }  }  class Player { /* more code here */ }  Which two are true?()

    • A、 This code will compile.
    • B、 This code demonstrates proper design of an is-a relationship.
    • C、 This code demonstrates proper design of a has-a relationship.
    • D、 A Java programmer using the Team class could remove Player objects from a Team object.

    正确答案:A,D

  • 第5题:

    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

  • 第6题:

    public class Threads4 {  public static void main (String[] args) {  new Threads4().go();  }  public void go() {  Runnable r = new Runnable() { public void run() {  System.out.print(”foo”);  }  };  Thread t = new Thread(r);  t.start();  t.start();  }  }  What is the result?() 

    • A、 Compilation fails.
    • B、 An exception is thrown at runtime.
    • C、 The code executes normally and prints „foo”.
    • D、 The code executes normally, but nothing is printed.

    正确答案:B

  • 第7题:

    Given:   10. class One {   11. void foo() { }   12. }   13. class Two extends One {   14. //insert method here   15. }   Which three methods, inserted individually at line 14, will correctly complete class Two?()

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

    正确答案:A,C,E

  • 第8题:

    多选题
    import java.util.*;  public class NameList {  private List names = new ArrayList();  public synchronized void add(String name) { names.add(name); }  public synchronized void printAll() {  for (int i = 0; i System.out.print(names.get(i) +“ “); }  }  public static void main(String[] args) {  final NameList sl = new NameList();  for(int i=0;i
    A

    An exception may be thrown at runtime.

    B

    The code may run with no output, without exiting.

    C

    The code may rum with output “A B A B C C “, then exit.

    D

    The code may ruin with output “A A A B C A B C C “, then exit.

    E

    The code may rum with output “A B C A B C A B C “, then exit.

    F

    The code may ruin with output “A B C A A B C A B C “, then exit.


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

  • 第9题:

    多选题
    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 */ }


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

  • 第10题:

    多选题
    Which three will compile and rim 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,D
    解析: 暂无解析

  • 第11题:

    单选题
    以下哪个方法可以用来获得进度条的当前进度值?()
    A

    public synchronized int getProgress()

    B

    public synchronized void setIndeterminate (boolean indeterminate)

    C

    public synchronized void setProgress(int progress)

    D

    Public final synchronized void incrementProgressBy(int diff)


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

  • 第12题:

    多选题
    31. // some code here  32. try {  33. // some code here  34. } catch (SomeException se) {  35. // some code here  36. } finally {  37. // some code here  38. }  Under which three circumstances will the code on line 37 be executed?()
    A

    The instance gets garbage collected.

    B

    The code on line 33 throws an exception.

    C

    The code on line 35 throws an exception.

    D

    The code on line 31 throws an exception.

    E

    The code on line 33 executes successfully.


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

  • 第13题:

    下列程序的输出结果为( )。 public class Reentrant { public synchronized void a() { b(); System.out.println("here I am, in a()"); } public synchronized void b() { System.out.println("here I am, in b()"); } public static void main(String args[ ]) { Reentrant r=new Reentrant(); r.a(); } }

    A.here I am, in a()/here I am, in b()

    B.hereI am, in b()/here I am, in a()

    C.here I am, in a()

    D.here I am, in b()


    正确答案:B
    解析:此题程序中类Reentrant定义了两个带有synchronized的方法,分别是a()和b()。在Reentrant类的main()方法中,Reentrant类的实例r调用了方法a(),在a()中调用b()。a()的执行过程中,线程的控制将请求并获得r的锁,并开始执行a()方法。由b()的定义可知,线程获得r的对象锁才能运行该方法,而此时r的锁已经由该线程获得,根据Java对象锁的可重入性,该线程将再次获得r的锁,并开始运行方法b()。

  • 第14题:

    void waitForSignal() {  Object obj = new Object();  synchronized (Thread.currentThread()) {  obj.wait();  obj.notify();  }  }  Which is true?() 

    • A、 This code may throw an InterruptedException.
    • B、 This code may throw an IllegalStateException.
    • C、 This code may throw a TimeoutException after ten minutes.
    • D、 This code will not compile unless “obj.wait()” is replaced with “((Thread) obj).wait()”.
    • E、 Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally.
    • F、 A call to notify() or notifyAll() from another thread may cause this method to complete normally.

    正确答案:B

  • 第15题:

    31. // some code here  32. try {  33. // some code here  34. } catch (SomeException se) {  35. // some code here  36. } finally {  37. // some code here  38. }  Under which three circumstances will the code on line 37 be executed?()

    • A、 The instance gets garbage collected.
    • B、 The code on line 33 throws an exception.
    • C、 The code on line 35 throws an exception.
    • D、 The code on line 31 throws an exception.
    • E、 The code on line 33 executes successfully.

    正确答案:B,C,E

  • 第16题:

    import java.util.*;  public class NameList {  private List names = new ArrayList();  public synchronized void add(String name) { names.add(name); }  public synchronized void printAll() {  for (int i = 0; i System.out.print(names.get(i) +“ “); }  }  public static void main(String[] args) {  final NameList sl = new NameList();  for(int i=0;i<2;i++) {  new Thread() {  public void ruin() {  sl.add(”A”);  sl.add(”B”);  sl.add(”C”);  sl.printAll();  }  }.start();  }  }  }  Which two statements are true if this class is compiled and run?()

    • A、 An exception may be thrown at runtime.
    • B、 The code may run with no output, without exiting.
    • C、The code may rum with output “A B A B C C “, then exit.
    • D、The code may ruin with output “A A A B C A B C C “, then exit.
    • E、 The code may rum with output “A B C A B C A B C “, then exit.
    • F、The code may ruin with output “A B C A A B C A B C “, then exit.

    正确答案:E,F

  • 第17题:

    Which three will compile and rim 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

  • 第18题:

    public class TestFive {  private int x;  public void foo() {  int current = x;  x = current + 1;  }  public void go() {  for(int i=0;i<5;i++) {  new Thread() {  public void run() {  foo();  System.out.print(x + “, “);  } }.start();  }}}  Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?()

    • A、 Move the line 12 print statement into the foo() method.
    • B、 Change line 7 to public synchronized void go() {.
    • C、 Change the variable declaration on line 3 to private volatile int x;.
    • D、 Wrap the code inside the foo() method with a synchronized( this ) block.
    • E、 Wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }.

    正确答案:A,D

  • 第19题:

    多选题
    Given:   10. class One {   11. void foo() { }   12. }   13. class Two extends One {   14. //insert method here   15. }   Which three methods, inserted individually at line 14, will correctly complete class Two?()
    A

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

    B

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

    C

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

    D

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

    E

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


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

  • 第20题:

    多选题
    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 */ }


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

  • 第21题:

    多选题
    public class Team extends java.util.LinkedList {  public void addPlayer(Player p) {  add(p);  }  public void compete(Team opponent) { /* more code here */ }  }  class Player { /* more code here */ }  Which two are true?()
    A

    This code will compile.

    B

    This code demonstrates proper design of an is-a relationship.

    C

    This code demonstrates proper design of a has-a relationship.

    D

    A Java programmer using the Team class could remove Player objects from a Team object.


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

  • 第22题:

    多选题
    public class TestFive {  private int x;  public void foo() {  int current = x;  x = current + 1;  }  public void go() {  for(int i=0;i<5;i++) {  new Thread() {  public void run() {  foo();  System.out.print(x + “, “);  } }.start();  }}}  Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?()
    A

    Move the line 12 print statement into the foo() method.

    B

    Change line 7 to public synchronized void go() {.

    C

    Change the variable declaration on line 3 to private volatile int x;.

    D

    Wrap the code inside the foo() method with a synchronized( this ) block.

    E

    Wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }.


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

  • 第23题:

    单选题
    现有:  1.  class Propeller2  {  2.   pulolic static void main (String[]args)//add code here?      3.    {  new Propeller2().topGo();  }      4.  5.void topGo()  //add code here?      6.    {   middleGo();  }      7.  8.void middleGo()  //add code here?  9. {   go();  System.out.println ("late middle");  }    void go()  //add code here?      12.    {throw new Exception();  }      13.  }  为使代码通过编译,需要在哪一行加入声明throws Exception?()
    A

    只在第11行

    B

    在第8行和第11行

    C

    在第5行、第8行和第11行

    D

    在第2行、第5行、第8行和第11行


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

  • 第24题:

    多选题
    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 */ }


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