




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
35道SCJP考试真题精解例题1: Choose the three valid identifiers from those listed below.A. IDoLikeTheLongNameClassB. $byteC. constD. _okE. 3_case解答:A, B, D点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头。关键字与保留字不能作为标示符。选项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. Set all references to the object to new values(null, for example).解答:A点评:在Java中垃圾收集是不能被强迫立即执行的。调用System.gc()或Runtime.gc()静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。所以选项B、D不正确。选项C的错误在于,System.gc()方法是不接受参数的。选项E中的方法可以使对象在下次垃圾收集器运行时被收集。例题3:以下是引用片段:Considerthefollowingclass: 1.classTest(inti) 2.voidtest(inti) 3.System.out.println(“Iamanint.”); 4. 5.voidtest(Strings) 6.System.out.println(“Iamastring.”); 7. 8. 9.publicstaticvoidmain(Stringargs) 10.Testt=newTest(); 11.charch=“y”; 12.t.test(ch); 13. 14.Which of the statements below is true?(Choose one.)A. Line 5 will not compile, because void 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 following 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.以下是引用片段:inti=0; if(i) System.out.println(“Hi”); B.以下是引用片段:booleanb=true; booleanb2=true; if(b=b2) System.out.println(“Sotrue”); C.以下是引用片段:inti=1; intj=2; if(i=1|j=2) System.out.println(“OK”);D.以下是引用片段:inti=1; intj=2; if(i=1&|j=2) System.out.println(“OK”);解答:B, C点评:选项A错,因为if语句后需要一个boolean类型的表达式。逻辑操作有、&、| 和 &、|,但是“&|”是非法的,所以选项D不正确。例题5:以下是引用片段:Whichtwodemonstrateahasarelationship?(Choosetwo) A.publicinterfacePerson publicclassEmployeeextendsPerson B.publicinterfaceShape publicinterfaceRectandleextendsShape C.publicinterfaceColorable publicclassShapeimplementsColorable D.publicclassSpecies publicclassAnimalprivateSpeciesspecies; E.interfaceComponent classContainerimplementsComponent privateComponentchildren; 解答: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 collection 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正确。由于采用了树形存储方式,将元素有序地组织起来,所以选项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);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 compile and run the following application? Choose all correct options.以下是引用片段:1.publicclassZ 2.publicstaticvoidmain(Stringargs) 3.newZ(); 4. 5. 6.Z() 7.Zalias1=this; 8.Zalias2=this; 9.synchronized(alias1) 10.try 11.alias2.wait(); 12.System.out.println(“DONEWAITING”); 13. 14.catch(InterruptedExceptione) 15.System.out.println(“INTERR UPTED”); 16. 17.catch(Exceptione) 18.System.out.println(“OTHEREXCEPTION”); 19. 20.finally 21.System.out.println (“FINALLY”); 22. 23. 24.System.out.println(“ALLDONE”); 25. 26.A. The application compiles but doesnt 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.publicclassMyTextAreaextendsTextArea 2.publicMyTextArea(intnrows,intncols) 3.enableEvents(AWTEvent.TEXT_ EVENT_MASK); 4. 5. 6.publicvoidprocessTextEvent (TextEventte) 7.System.out.println(“Processingatextevent.”); 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 and 8, the following code should appear: cessTextEvent(te).解答:A, B, E点评:由于类是public,所以文件名必须与之对应,选项A正确。如果不在2、3行之间加上super(nrows,ncols)的话,则会调用无参数构建器TextArea(), 使nrows、ncols信息丢失,故选项B正确。在Java2中,所有的事件处理方法都不返回值,选项C、D错误。选项E正确,因为如果不加cessTextEvent(te),注册的listener将不会被唤醒。11、Which statement about the garbage collection mechanism are true?A. Garbage collection require additional programe code in cases where multiple threads are running.B. The programmer can indicate that a reference through a local variable is no longer of interest.C. The programmer has a mechanism that explicity and immediately frees the memory used by Java objects.D. The garbage collection mechanism can free the memory used by Java Object at explection time.E. The garbage collection system never reclaims memory from objects while are still accessible to running user threads.答案:B、EJAVA的垃圾回收机制是通过一个后台系统级线程对内存分配情况进行跟踪实现的,对程序员来说是透明的,程序员没有任何方式使无用内存显示的、立即的被释放。而且它是在程序运行期间发生的。答案B告诉我们程序员可以使一个本地变量失去任何意义,例如给本地变量赋值为“null”;答案E告诉我们在程序运行期间不可能完全释放内存。12、Give the following method:以下是引用片段:1)publicvoidmethod() 2)Stringa,b; 3)a=newString(“helloworld”); 4)b=newString(“gameover”); 5)System.out.println(a+b+”ok”); 6)a=null; 7)a=b; 8)System.out.println(a); 9)In the absence of compiler optimization, which is the earliest point the object a refered is definitely elibile to be garbage collection.A. before line 3B.before line 5C. before line 6D.before line 7E. Before line 9答案:D第6行将null赋值给a以后,a以前保存的引用所指向的内存空间就失去了作用,它可能被释放。所以对象a可能最早被垃圾回收是在第7行以前,故选择D选项。13、 In the class java.awt.AWTEvent,which is the parent class upon which jdk1.1 awt events are based there is a method called getID which phrase accurately describes the return value of this method?A. It is a reference to the object directly affected by the cause of the event.B. It is an indication of the nature of the cause of the event.C. It is an indication of the position of the mouse when it caused the event.D. In the case of a mouse click, it is an indication of the text under the mouse at the time of the event.E. It tells the state of certain keys on the keybord at the time of the event.F. It is an indication of the time at which the event occurred.答案:B请查阅JAVA类库。getID方法的返回值是“event type”。在认证考试中,总会有类似的书本以外的知识,这只能靠多实践来增长知识了。14、Which statement about listener is true?A. Most component allow multiple listeners to be added.B. If multiple listener be add to a single component, the event only affected one listener.C. Component don?t allow multiple listeners to be add.D. The listener mechanism allows you to call an addXxxxListener method as many times as is needed, specifying as many different listeners as your design require.答案:A、D控件可以同时使用多个“addXxxxListener”方法加入多个监听器。并且当多个监听器加入到同一控件中时,事件可以响应多个监听器,响应是没有固定顺序的。15、Give the following code:以下是引用片段:publicclassExample publicstaticvoidmain(Stringargs) intl=0; do System.out.println(“Doingitforlis:”+l); while(-l0) System.out.println(“Finish”); Which well be output:A. Doing it for l is 3B. Doing it for l is 1C. Doing it for l is 2D. Doing it for l is 0E. Doing it for l is ?C1F. Finish答案:D、F本题主要考察考生对流程控制的掌握情况。这是当型循环,条件为真执行,条件为假则退出。循环体至少执行一次,故会输出D。循环体以外的语句总会被执行,故输出F。16、Give the code fragment:以下是引用片段:1)switch(x) 2)case1:System.out.println(“Test1”);break; 3)case2: 4)case3:System.out.println(“Test2”);break; 5)default:System.out.println(“end”); 6)which value of x would cause “Test 2” to the output:A. 1B. 2C. 3D. default答案:B.C在开关语句中,标号总是不被当做语句的一部分,标号的作用就是做为条件判断而已,一旦匹配成功,就执行其后的语句,一直遭遇break语句为止。(包括default语句在内)17、Give incompleted method:以下是引用片段:1) 2)if(unsafe()/dosomething 3)elseif(safe()/dotheother 4)The method unsafe() well throe an IOException, which completes the method of declaration when added at line one?A. public IOException methodName()B. public void methodName()C. public void methodName() throw IOExceptionD. public void methodName() throws IOExceptionE. public void methodName() throws Exception答案:D、FIOException异常类是Exception的子类。根据多态性的定义,IOException对象也可以被认为是Exception类型。还要注意在方法声明中抛出异常应用关键字“throws”。18、 Give the code fragment:以下是引用片段:if(x4) System.out.println(“Test1”); elseif(x9) System.out.println(“Test2”); else System.out.println(“Test3”); Whichrangeofvaluexwouldproduceofoutput“Test2”?A. x4C. x9D. None答案:D只有两种情况:大于4时输出“Test1”,小于等于4时输出“Test3”。19、Give the following method:以下是引用片段:publicvoidexample() try unsafe(); System.out.println(“Test1”); catch(SafeExceptione)System.out.println(“Test2”); finallySystem.out.println(“Test3”); System.out.println(“Test4”);Which will display if method unsafe () run normally?A. Test 1B. Test 2C. Test 3D. Test 4答案:A、C、D在正常情况下,打印Test1、Test3、Test4;在产生可捕获异常时打印Test2、Test3、Test4;在产生不可捕获异常时,打印Test3,然后终止程序。注意finally后面的语句总是被执行。20、Which method you define as the starting point of new thread in a class from which new the thread can be excution?A. public void start()B. public void run()C. public void int()D. public static void main(String args)E. public void runnable()答案:B线程的执行是从方法“run( )”开始的,该方法是由系统调用的。程序员手工调用方法start(),使线程变为可运行状态。21、Given the following class definition:以下是引用片段:classA protectedinti; A(inti) this.i=i; which of the following would be a valid inner class for this class?Select all valid answers:A. class BB. class B extends AC. class B extends AB()System.out.println(“i=”+i);D. class Bclass AE. class A答案:A此题考查内部类及关键字“super”的用法。内部类不能与外部类同名。另外,当B继承A时,A中的构造函数是带参数的,B中缺省构造函数的函数体为空;而JAVA编译器会为空构造函数体自动添加语句“super();”调用父类构造函数,更进一步是调用父类的参数为空的构造函数。而父类中没有参数为空的构造函数。22、Which modifier should be applied to a method for the lock of object this to be obtained prior to excution any of the method body?A. synchronizedB. abstractC. finalD. staticE. public答案:A此关键字可以在两个线程同时试图访问某一数据时避免数据毁损。23、The following code is entire contents of a file called Example.java,causes precisely one error during compilation:以下是引用片段:1)classSubClassextendsBaseClass 2) 3)classBaseClass() 4)Stringstr; 5)publicBaseClass() 6)System.out.println(“ok”); 7)publicBaseClass(Strings) 8)str=s; 9)publicclassExample 10)publicvoidmethod() 11)SubClasss=newSubClass(“hello”); 12)BaseClassb=newBaseClass(“world”); 13) 14)Which line would be cause the error?A. 9 B. 10 C. 11 D.12答案:C当一个类中未显式定义构造函数时,缺省的构造函数是以类名为函数名,参数为空,函数体为空。虽然父类中的某一构造函数有字符串参数s,但是子类继承父类时并不继承构造函数,所以它只能使用缺省构造函数。故在第11行出错。24、Which statement is correctly declare a variable a which is suitable for refering to an array of 50 string empty object?A. String aB. String aC. char aD. String a50F. Object a50答案:A、B注意,题中问的是如何正确声明一个一维数组,并非实例化或者初始化数组25、Give the following java source fragement:以下是引用片段:/pointx publicclassInteresting /dosomething Which statement is correctly Java syntax at point x?A. import java.awt.*;B.package mypackageC. static int PI=3.14D. public class MyClass/do other thing E. class MyClass/do something答案:A、EX处可以是一个输入,包的定义,类的定义。由于常量或变量的声明只能在类中或方法中,故不能选择C;由于在一个文件中只能有一个public类,故不能选择D。26、Give this class outline:以下是引用片段:classExample privateintx; /restofclassbody Assuming that x invoked by the code java Example, which statement can made x be directly accessible in main() method of Example.java?A. Change private int x to public int xB. change private int x to static int xC. Change private int x to protected int xD. change private int x to final int x答案:B静态方法除了自己的参数外只能直接访问静态成员。访问非静态成员,必须先实例化本类的一个实例,再用实例名点取。27、 the piece of preliminary analsis work describes a class that will be used frequently in many unrelated parts of a project“The polygon object is a drawable, A polygon has vertex information stored in a vector, a color, length and width.”Which Data type would be used?A. VectorB. intC. StringD. ColorE. Date答案:A、B、Dpolygon的顶点信息存放在Vector类型的对象内部,color定义为Color,length和width定义为int。注意,这是考试中常见的题型。28、 A class design requires that a member variable should be accessible only by same package, which modifer word should be used?A. protectedB. publicC. no modiferD. private答案:C此题考点是高级访问控制。请考生查阅高级访问控制说明表格。29、Which declares for native method in a java class corrected?A. public native void method()B. public native void method();C. public native method();D. public void method()native;E. public void native method();答案:Bnative关键字指明是对本地方法的调用,在JAVA中是只能访问但不能写的方法,它的位置在访问权限修饰语的后面及返回值的前面。30、Which modifer should be applied to a declaration of a class member variable for the value of variable to remain constant after the cre
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- dr知识培训课件
- 第5课《你是人间的四月天》教学设计 统编版语文九年级上册
- 2025年老年口腔护理题库及答案
- 2025年口腔护理的题库及答案
- 2024年海南儋州市专职网格员招聘笔试真题
- 2024秋九年级历史上册 第三单元 近代社会的发展与终结 第17课 电气时代的来临说课稿 北师大版
- 2024年邯郸市教育局市直学校选聘博硕人才笔试真题
- 2025年公共卫生知识试卷(有答案)
- 环保法规与行业自律-洞察及研究
- 服装结构制图的一般规定教学设计中职专业课-服装结构制图-服装设计与工艺-轻工纺织大类
- 辽宁省民间信仰管理办法
- 财务信息化系统建设-洞察阐释
- 学堂在线 新闻摄影 期末考试答案
- 脑瘫个案护理
- 2025年全国新高考英语II卷试题解析及复习备考策略(课件)
- 课本剧《霸王别姬》剧本【3篇】
- 2025年营养土项目可行性研究报告
- 2025至2030年中国乙肝疫苗行业市场发展模式及未来前景分析报告
- 作文写作(解析版)-2025年中考语文一模试题分类汇编(贵州专用)
- 人工智能技术研发股东出资合作框架协议
- 学校教职工网络安全培训
评论
0/150
提交评论