版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、SUN认证Java2程序员考试题及答案Java带给你的并不仅仅是面向对象、开放、平台无关、易用、安全和“Write once, run anywhere”等软件开发方面的优势,更重要的一点是,它提供了一种新颖的表达思想的方式,一种全新的思维模式。下面一起来看看Java2程序员考试题及答案!例题1:Choose the three valid identifiers from those listed below.A. IDoLikeTheLongNameClassB. $byteC. constD. _okE. 3_case解答:A, B, D点评:Java中的标示符必须是字母、美元符($)或
2、下划线(_)开头。关键字与保留字不能作为标示符。选项C中的const是Java的保留字,所以不能作标示符。选项E中的3_case以数字开头,违反了Java的规则。例题2:How can you force garbage collection of an object?A. Garbage collection cannot be forcedB. Call System.gc().C. Call System.gc(), passing in a reference to the object to be garbage collected.D. Call Runtime.gc().E. S
3、et all references to the object to new values(null, for example).解答:A点评:在Java中垃圾收集是不能被强迫立即执行的。调用System.gc()或Runtime.gc()静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。所以选项B、D不正确。选项C的错误在于,System.gc()方法是不接受参数的。选项E中的方法可以使对象在下次垃圾收集器运行时被收集。例题3:Consider the following class:1. class Test(int i) 2. void test(int i) 3.
4、 System.out.println(“I am an int.”);4. 5. void test(String s) 6. System.out.println(“I am a string.”);7. 8.9. public static void main(String args) 10. Test t=new Test();11. char ch=“y”;12. t.test(ch);13. 14. Which of the statements below is true?(Choose one.)A. Line 5 will not compile, because void
5、methods cannot be overridden.B. Line 12 will not compile, because there is no version of test() that rakes a char argument.C. The code will compile but will throw an exception at line 12.D. The code will compile and produce the following output: I am an int.E. The code will compile and produce the f
6、ollowing output: I am a String.解答:D点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。例题4:Which of the following lines of code will compile without error?A.int i=0;if (i) System.out.println(“Hi”);B.boolean b=true;boolean b2=true;if(b=b2) System.out.println(“So true”);C.int i=1;in
7、t j=2;if(i=1| j=2)System.out.println(“OK”);D.int i=1;int j=2;if (i=1 &| j=2)System.out.println(“OK”);解答:B, C点评:选项A错,因为if语句后需要一个boolean类型的表达式。逻辑操作有、&、| 和 &&、|,但是“&|”是非法的,所以选项D不正确。例题5:Which two demonstrate a "has a" relationship? (Choose two)A. public interface Person pub
8、lic class Employee extends Person B. public interface Shape public interface Rectandle extends Shape C. public interface Colorable public class Shape implements Colorable D. public class Species public class Animalprivate Species species;E. interface Component class Container implements Componentpri
9、vate Component children;解答:D, E点评: 在Java中代码重用有两种可能的方式,即组合(“has a”关系)和继承(“is a”关系)。“has a”关系是通过定义类的属性的方式实现的;而“is a”关系是通过类继承实现的。本例中选项A、B、C体现了“is a”关系;选项D、E体现了“has a”关系。例题6:Which two statements are true for the class java.util.TreeSet? (Choose two)A. The elements in the collection are ordered.B. The co
10、llection is guaranteed to be immutable.C. The elements in the collection are guaranteed to be unique.D. The elements in the collection are accessed using a unique key.E. The elements in the collection are guaranteed to be synchronized解答:A, C点评:TreeSet类实现了Set接口。Set的特点是其中的元素惟一,选项C正确。由于采用了树形存储方式,将元素有序地
11、组织起来,所以选项A也正确。例题7:True or False: Readers have methods that can read and return floats and doubles.A. TureB. False解答:B点评: Reader/Writer只处理Unicode字符的输入输出。float和double可以通过stream进行I/O.例题8:What does the following paint() method draw?1. public void paint(Graphics g) 2. g.drawString(“Any question”, 10, 0);
12、3. A. The string “Any question?”, with its top-left corner at 10,0B. A little squiggle coming down from the top of the component.解答:B点评:drawString(String str, int x, int y)方法是使用当前的颜色和字符,将str的内容显示出来,并且最左的字符的基线从(x,y)开始。在本题中,y=0,所以基线位于最顶端。我们只能看到下行字母的一部分,即字母y、q的下半部分。例题9:What happens when you try to comp
13、ile 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 (Interrupted
14、Exception e) 15. System.out.println(“INTERRUPTED”);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
15、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的锁,进入等待池。但此后没有线程调用
16、对象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(Te
17、xtEvent te) 7. System.out.println(“Processing a text event.”);8. 9. A. The source code must appear in a file called MyTextArea.javaB. 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 an
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 文化场馆应急供水方案及演练
- 医药门店库存预警实施方案
- 职业病防护岗位安全管理制度
- 乡村道路工程质量评估报告
- 压力管道巡检安全管理制度
- 乡村道路施工图设计说明
- 食品加工企业隐患排查整改专项报告
- 算力中心数据安全管理规范
- 屋建筑与装饰工程BIM应用方案
- 2026教师职称-天津-天津教师职称(基础知识、综合素质、初中美术)历年参考题库含答案详解
- 深圳网约车从业资格证模拟考试题库(含答案)
- 项目商务管理课件教学
- DBJ-T15-81-2022 建筑混凝土结构耐火设计技术规程
- 养老机构管理课件
- 机关保密室管理制度
- 《车站信号自动控制》复习题库
- 铁路电子客票应急处置
- 2025年中国中信集团招聘笔试参考题库含答案解析
- 袖阀管注浆合同
- 2024年冬季N0M世界青少年数学思维研学活动模拟题4年级
- QC/T 985-2024汽车热反射镀膜夹层前风窗玻璃
评论
0/150
提交评论