Exercise of the Thread(2)

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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,此外,当运行静态方法时,它不属于这个对象;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航