频道栏目
首页 > 资讯 > JAVA > 正文

JAVA认证历年真题:SCJP考试真题和解析4

16-06-07        来源:[db:作者]  
收藏   我要投稿
  例题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.processTextEvent(te),注册的listener将不会被唤醒。

  1.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.

  1。B、E

  JAVA的垃圾回收机制是通过一个后台系统级线程对内存分配情况进行跟踪实现的,对程序员来说是透明的,程序员没有任何方式使无用内存显示的、立即的被释放。而且它是在程序运行期间发生的。

  答案B告诉我们程序员可以使一个本地变量失去任何意义,例如给本地变量赋值为“null”;答案E告诉我们在程序运行期间不可能完全释放内存。

  2. Give the following method:

  1) public void method( ){

  2) String a,b;

  3) a=new String(“hello world”);

  4) b=new String(“game over”);

  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 3

  B.before line 5

  C. before line 6

  D.before line 7

  E. Before line 9

  2。D

  第6行将null赋值给a以后,a以前保存的引用所指向的内存空间就失去了作用,它可能被释放。所以对象a可能最早被垃圾回收是在第7行以前,故选择D选项。

  3. 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

相关TAG标签
上一篇:JAVA认证历年真题:SCJP考试真题和解析5
下一篇:JAVA认证历年真题:SCJP考试真题和解析3
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站