多选题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(){ synchronized(Object.class){/* code here */}Fvoid go(){ Object o = new Object(); synchronized(o){/* code here */}
多选题
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 */}
参考解析
解析:
暂无解析
相关考题:
What happens when you try to compile and run the following program?class Mystery{String s;public static void main(String[] args){Mystery m=new Mystery();m.go();}void Mystery(){s=”constructor”;}void go(){System.out.println(s);}}()A.this code will not compileB.this code compliles but throws an exception at runtimeC.this code runs and “constructor” in the standard outputD.this code runs and writes “null” in the standard output
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 */ }
Given:Which method will complete this class?() A.public int compareTo(Object o){/*more code here*/}B.public int compareTo(Score other){/*more code here*/}C.public int compare(Score s1,Score s2){/*more code here*/}D.public int compare(Object o1,Object o2){/*more code here*/}
Given:Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?() A.move the line 12 print statement into the foo() methodB.change line 7 to public synchronized void go() {C.change the variable declaration on line 2 to private volatile int x;D.wrap the code inside the foo() method with a synchronized( this ) blockE.wrap the for loop code inside the go() method with a synchronized block synchronized(this){ //for loop code here }
下列程序的输出结果为( )。 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()
下列程序的输出结果为( )。 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()
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 */ }
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.
现有: 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行
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.
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.
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;i2;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.
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 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 */ } }
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.
public class TestFive { private int x; public void foo() { int current = x; x = current + 1; } public void go() { for(int i=0;i5;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 }.
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 */ }
多选题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?()Apublic void foo() { /* more code here */ }Bprivate void foo() { /* more code here */ }Cprotected void foo() { /* more code here */ }Dint foo() { /* more code here */ }Evoid foo() { /* more code here */ }
多选题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;iAAn exception may be thrown at runtime.BThe code may run with no output, without exiting.CThe code may rum with output “A B A B C C “, then exit.DThe code may ruin with output “A A A B C A B C C “, then exit.EThe code may rum with output “A B C A B C A B C “, then exit.FThe code may ruin with output “A B C A A B C A B C “, then exit.
多选题Given: Which three methods, inserted individually at line 14, will correctly complete class Two?()Aint foo() { /* more code here */ }Bvoid foo() { /* more code here */ }Cpublic void foo() { /* more code here */ }Dprivate void foo() { /* more code here */ }Eprotected void foo() { /* more 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() {synchronized(Object.class) { /* code here */ }Fvoid go() {Object o = new Object();synchronized(o) { /* code here */ }
多选题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?()AThis code will compile.BThis code demonstrates proper design of an is-a relationship.CThis code demonstrates proper design of a has-a relationship.DA Java programmer using the Team class could remove Player objects from a Team object.
多选题Which three will compile and rim 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() { synchronized(Object.class) { /* code here */ } }Fvoid go() { Object o = new Object(); synchronized(o) { /* code here */ } }
多选题public class TestFive { private int x; public void foo() { int current = x; x = current + 1; } public void go() { for(int i=0;i5;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, ?()AMove the line 12 print statement into the foo() method.BChange line 7 to public synchronized void go() {.CChange the variable declaration on line 3 to private volatile int x;.DWrap the code inside the foo() method with a synchronized( this ) block.EWrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }.
单选题以下哪个方法可以用来获得进度条的当前进度值?()Apublic synchronized int getProgress()Bpublic synchronized void setIndeterminate (boolean indeterminate)Cpublic synchronized void setProgress(int progress)DPublic final synchronized void incrementProgressBy(int diff)
单选题现有: 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行
多选题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?()AThe instance gets garbage collected.BThe code on line 33 throws an exception.CThe code on line 35 throws an exception.DThe code on line 31 throws an exception.EThe code on line 33 executes successfully.
多选题class One { void foo() {} } class Two extends One { //insert method here } Which three methods, inserted individually at line 14, will correctly complete class Two?()Aint foo() { /* more code here */ }Bvoid foo() { /* more code here */ }Cpublic void foo() { /* more code here */ }Dprivate void foo() { /* more code here */ }Eprotected void foo() { /* more code here */ }