SCJP考试题310-025(第二套)51-91/147

来源:java认证发布时间:2012-11-12 13:05:39java认证视频


Question No 54
Which statement is true?
A. If only one thread is blocked in the wait method of an object, and another thread executes the
modify on that same object, then the first thread immediately resumes execution.
B. If a thread is blocked in the wait method of an object, and another thread executes the notify
method on the same object, it is still possible that the first thread might never resume execution.
C. If a thread is blocked in the wait method of an object, and another thread executes the notify
method on the same object, then the first thread definitely resumes execution as a direct and sole
consequence of the notify call.
D. If two threads are blocked in the wait method of one object, and another thread executes the notify
method on the same object, then the first thread that executed the wait call first definitely resumes
execution as a direct and sole consequence of the notify call.
Answer: B
Question No 55
Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Calling the yield method.
B. Calling the wait method on an object.
C. Calling the notify method on an object.
D. Calling the notifyAll method on an object.
E. Calling the start method on another Thread object.
Answer: C, D
Question No 56
Which two can be used to create a new Thread? (Choose Two)
A. Extend java.lang.Thread and override the run method.
B. Extend java.lang.Runnable and override the start method.
C. Implement java.lang.thread and implement the run method.
D. Implement java.lang.Runnable and implement the run method.
E. Implement java.lang.Thread and implement the start method.
Answer: A, D

Question No 57
Given:
1. public class SyncTest (
2. private int x;
3. private int y;
4. private synchronized void setX (int i) (x=1;)
5. private synchronized void setY (int i) (y=1;)
6. public void setXY(int 1)(set X(i); setY(i);)
7. public synchronized Boolean check() (return x !=y;)
8. )
Under which conditions will check () return true when called from a different class?
A. Check() can never return true.
B. Check() can return true when setXY is called by multiple threads.
C. Check() can return true when multiple threads call setX and setY separately.
D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.
Answer: B
Question No 58
Exhibit:
1. class A implements runable (
2. int i;
3. public void run () (
4. try (
5. thread.sleep(5000);
6. i= 10;
7. ) catch(InterruptedException e) {}
8. )
9. )
10.
11. public class Test {
12. public static void main (string args[]) (
13. try (
14. A a = new A ();
15. Thread t = new Thread (a);
16. t.start();
17.
18. int j= a.i;
19.
20. ) catch (Exception e) {}
21. )
22. )
Which statement al line 17 will ensure that j=10 at line 19?
A. a.wait();
B. t.wait();
C. t.join();
D. t.yield();
E. t.notify();
F. a.notify();
G. t.interrupt();
Answer: C
Question No 59
Exhibit:
1. public class X implements Runnable (
2. private int x;
3. private int y;
4.
5. public static void main(String [] args) (
6. X that = new X();
7. (new Thread(that)) . start( );
8. (new Thread(that)) . start( );
9. )
10.
11. public synchronized void run( ) (
12. for (;;) (
13. x++;
14. y++;
15. System.out.printIn(“x = “ + x + “, y = “ + y);
16. )
17. )
18. )
What is the result?
A. An error at line 11 causes compilation to fail.
B. Errors at lines 7 and 8 cause compilation to fail.
C. The program prints pairs of values for x and y that might not always be the same on the same line
(for example, “x=2, y=1”)
D. The program prints pairs of values for x and y that are always the same on the same line (for
example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by
“x=1, y=1”)
E. The program prints pairs of values for x and y that are always the same on the same line (for
example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by
“x=2s, y=2”)
Answer: E
QUESTION NO: 60
Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Existing from a synchronized block.
B. Calling the wait method on an object.
C. Calling notify method on an object.
D. Calling read method on an InputStream object.
E. Calling the SetPriority method on a Thread object.
Answer: A, C

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答