1、 2.voidtest(int3.System.out.println(“Iamanint.”);4. 5.test(Strings)6.astring.”);7.8. 9.publicstaticmain(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
2、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
3、位长的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;b2=true;if(b=b2)System.out.println(“Sotrue”);C.i=1;j=2;if(i=1|j=2) System.out.println(“OK”);D.(i=1&|B, C选项A错,因为if语句后需
4、要一个boolean类型的表达式。逻辑操作有、&、| 和 &、|,但是“&|”是非法的,所以选项D不正确。例题5:Whichtwodemonstratehasarelationship?(Choosetwo) A.interfacePersonpublicEmployeeextendsPersonB.ShapeRectandleC.ColorableimplementsColorable D.SpeciesAnimalprivateSpeciesspecies;E.ComponentclassContainerComponent privateComponentchildren;D, E 在J
5、ava中代码重用有两种可能的方式,即组合(“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 immutabl
6、e.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 synchronizedA, CTreeSet类实现了Set接口。Set的特点是其中的元素惟一,选项C正确。由于采用了树形存储方式,将元素有序地组织起来,所以选项A也正确。例题7:True or False: Readers ha
7、ve methods that can read and return floats and doubles.A. TureB. FalseB 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-le
8、ft corner at 10,0B. A little squiggle coming down from the top of the component.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 correc
9、t options.1.Zmain(Stringargs)newZ();5. Z()alias1=this;8.alias2synchronized(alias1)tryalias2.wait();System.out.println(“DONEWAITING”);catch(InterruptedExceptione)15.System.out.println(“INTERR UPTED”);16.17.(Exception18.System.out.println(“OTHEREXCEPTION”);19.20.finally21.System.out.println (“FINALLY”
10、);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”在
11、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.MyTextAreaTextAreaMyTextArea(intnrows,intncols)enableEv
12、ents(AWTEvent.TEXT_ EVENT_MASK);processTextEvent (TextEventte)System.out.println(“Processingtextevent.”);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 li
13、ne 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,
14、ncols)的话,则会调用无参数构建器TextArea(), 使nrows、ncols信息丢失,故选项B正确。在Java2中,所有的事件处理方法都不返回值,选项C、D错误。选项E正确,因为如果不加super.processTextEvent(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
15、 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
16、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 fo
17、llowing method:1)method() 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
18、.A. before line 3B.before line 5C. before line 6D.before line 7E. Before line 9第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 acc
19、urately 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
20、, 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.请查阅JAVA类库。getID方法的返回值是“event type”。在认证考试中,总会有类似的书本以外的知识,这只能靠多实践来增长知识了。14、Which state
21、ment 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 a
22、s many times as is needed, specifying as many different listeners as your design require.A、D控件可以同时使用多个“addXxxxListener”方法加入多个监听器。并且当多个监听器加入到同一控件中时,事件可以响应多个监听器,响应是没有固定顺序的。15、Give the following code:Example argsl=0;do System.out.println(“Doingitforlis:”+l);while(-l0) System.out.println(“Finish”); Whic
23、h 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. FinishD、F本题主要考察考生对流程控制的掌握情况。这是当型循环,条件为真执行,条件为假则退出。循环体至少执行一次,故会输出D。循环体以外的语句总会被执行,故输出F。16、Give the code fragment:switch(x) case1:System.out.println(“Test1”);break;2:3:2”);default:System.out.println(“end”);which value of x would cause “Test 2” to the output:A. 1B. 2C. 3D. defaultB.C在开关语句中,标号总是不被当做语句的一部分,标号的作用就是做为条件判断而已,一旦匹配成功,就执行其后的语句,一直遭遇break语句为止。(包括default语句在内)17、Give incompleted method:1) if(unsafe()/dosomething elseif(safe()/doother The method un
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1