您的位置:
首页 >> 资讯资料 >> IT培训 >> 正文:SUN认证Java2程序员考试(SCJP) 试题解析(3)

SUN认证Java2程序员考试(SCJP) 试题解析(3)

What happens when you try to compile and run the following application? Choose all
correct options.   
1. public class Z {   
2. public static void main(String[] args) {   
3. new Z();   
4. }   
5.   
6. Z() {   
7. Z alias1 = this;   
8. Z alias2 = this;   
9. synchronized(alias1) {   
10. try {   
11. alias2.wait();   
12. System.out.println(“DONE WAITING”);   
13. }   
14. catch (InterruptedException e) {   
15. System.out.println(“INTERR   
UPTED”);   
16. }   
17. catch (Exception e) {   
18. System.out.println(“OTHER EXCEPTION”);   
19. }   
20. finally {   
21. System.out.println   
(“FINALLY”);   
22. }   
23. }   
24. System.out.println(“ALL DONE”);   
25. }   
26. }   
A. The application compiles but doesn’t print anything.   
B. The application compiles and print “DONE WAITING”   
C. The application compiles and print “FINALLY”   
D. The application compiles and print “ALL DONE”   
E. The application compiles and print “INTERRUPTED”   
解答:A   
  点评:在Java中,每一个对象都有锁。任何时候,该锁都至多由一个线 
alias1与alias2指向同一对象Z,在执行第11行前,线程拥有对象Z的锁。在执行完第11行以后,该线程释放了对象Z的锁,进入等待池。但此后没有线程调用对象Z的notify()和notifyAll()方法,所以该进程一直处于等待状态,没有输出。   

例题10:   
Which statement or statements are true about the code listed below? Choose three.   
1. public class MyTextArea extends TextArea {   
2. public MyTextArea(int nrows, int ncols) {   
3. enableEvents(AWTEvent.TEXT_   
EVENT_MASK);   
4. }   
5.   
6. public void processTextEvent   
(TextEvent te) {   

7. System.out.println(“Processing a text event.”);   
8. }   
9. }   
A. The source code must appear in a file called MyTextArea.java   
B. Between lines 2 and 3, a call should be made to super(nrows, ncols) so that the
new component will have the correct size.   
C. At line 6, the return type of processTextEvent() should be declared boolean,
 not void.   
D. Between lines 7 and 8, the following code should appear: return true.  
E. Between lines 7 and 8, the following code should appear: super.processTextEvent
(te).   
解答:A, B, E   
  点评:由于类是public,所以文件名必须与之对应,选项A正确。如果不在2、3行之间加上super(nrows,ncols)的话,则会调用无参数构建器TextArea(), 使nrows、ncols信息丢失,故选项B正确。在Java2中,所有的事件处理方法都不返回值,选项C、D错误。选项E正确,因为如果不加super.processTextEv
listener将不会被唤醒。   

SCJP考试中的几点注意:   

● 深刻理解面向对象的思想   
  Java是一种纯粹的面向对象的程序设计语言。在正式使用Java做开发之前,必须将我们的思维方式转入一个彻底的面向对象的世界。做不到这一点,就无法体会Java语言的精髓,写不出地道的Java程序。当然,你也无法彻底理解Java中的基本概念和他们之间的联系与区别,如例题3、例题5。你可以学到Java的语法规则,却不能看到Java的灵魂。   

● 对概念细节的精确把握   
  通过例题我们可以看到,SCJP的考察点相当细致。如例题1、2、4、7、8。所以只有对Java的概念、语法、规则了然于心,才能在考场上应对自如。   

● 适量的练习   
  程序设计是一项实践性很强的技术。只有上机实践,才能使课本中的理论、头脑中的思想通过你的双手成为一行行代码,完成规定的目标。虽然SCJP考试不考操作与编程,但有大量的程序阅读,如例题3、4、9、10。如果你自己写过许多代码的话,这种题就是小菜一碟。   

● 广泛的交流   
  善于交流是优秀程序员必备的技能,也是你解决疑难,提高水平的捷径。国内外有很多与Java认证相关的优秀网站和论坛,都是学习Java的宝库。同时,一些很棒的模考软件,如Jxam、JTest、 Javacert等,以及著名的模考题如MarcusGreen的三套题均可以找到。 
【作者:本站编辑┊来源:学习联盟┊2005-07-17】TAGS:
评论与咨询 内容报错
姓名: 电话: 邮箱: 地址:

  • ·本咨询平台是部分培训机构与本站指定的网上报名、咨询的专用平台,您可以通过此处提交您的信息,我们或该机构会根据您所提交的信息及时给予回复;
  • ·为了更好的问您服务,请填写您真实的姓名和相关联系方式,以便我们能及时给您答复;
  • ·不得提交有关违反国家互联网规定的不良信息,对于违规者我们有权追究你的法律责任!若有任何问题请 联系我们
关于我们 | 服务条款 | 广告服务 | 客服中心 | 网站导航 - 设为首页 - 收藏本站
Copyright © 2006-2008 www.0512edu.com.cn All Rights Reserved
苏州培训资讯网 版权所有
Powered By:AspArticle2.0 在远方