|
|
Exercise of the Thread(2) |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
11.Which three are methods of the Object class?(Choose three.)
A. notify(); B. notifyAll(); C. isInterrupted(); D. synchronized(); E. interrupt(); F. wait(long msecs); G. sleep(long msecs); H. yield();
(A.B.F). Java Doc
12.Given the following.
1.public class WaitTest{ 2. public static void main(String []args){ 3. System.out.print("1 "); 4. synchroized(args){ 5. System.out.print("2 "); 6. try{ 7. args.wait(); 8. } 9. catch(InterruptedException e){} 10. } 11. System.out.print("3 "); 12. } 13.}
what is the result of trying of compile and run this program?
A. It fails to compile because the IllegalMonitorStateException of wait() is not dealt with in line 7.
B. 1 2 3
C. 1 3
D. 1 2
E. At runtime,it throws an IllegalMonitorStateException when trying to wait.
F. It will fail to compile because it has to be synchronized on the this object.
(D).将打印1和2,但是,因为没有其他线程通告主线程,他们不会返回调用WAIT,所以3不会被打印,程序会冻结在第7行; A是错误的,因为IllegalMonitorStateException是一个不检测的异常,所以它不会进行明确的处理; F是错误的,因为任何OBJECT都可以使用synchroized,此外,当运行静态方法时,它不属于这个对象;
|
|
相关文章:相关软件: |
|