a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 60|回复: 0

[考试试题] JAVA认证历年真题:SCJP考试真题和解析一(4)

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
 例题10:   Which statement or statements are true about the code listed below? Choose three.
& _7 m2 S& f, J9 p9 D  1. public class MyTextArea extends TextArea { ; {+ S0 p$ h# J" _8 S2 ]
  2. public MyTextArea(int nrows, int ncols) { ; F% J* M8 Y+ a# O& V
  3. enableEvents(AWTEvent.TEXT_ 4 k# R( x5 I# M2 {
  EVENT_MASK);
0 O# V- h% K7 Y! G; z5 @  4. } ( t7 n! o7 F9 l- ]: I, Z
  5.
1 \6 d3 R2 Z6 H7 P6 w% p8 U  6. public void processTextEvent
! H. M- ~2 Y" D9 B+ c* G* {* Z  (TextEvent te) { , e; K0 m/ h. W. v$ }& J
  7. System.out.println(“Processing a text event.”);
  l% x& ?$ m. B0 j+ i' f- B$ {+ O  8. }
: {% ]) h7 S& E* K: f  9. }
: z7 y- \% r  P" ]% X% \  i  A. The source code must appear in a file called MyTextArea.java
5 H0 l# e) x6 p) Z6 @+ {  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.
) B, R& ]1 y' w  C. At line 6, the return type of processTextEvent() should be declared boolean, not void. 7 y+ R" d6 r% E  o) p
  D. Between lines 7 and 8, the following code should appear: return true. " [: V* O" t2 E! C: q% Q' H+ L
  E. Between lines 7 and 8, the following code should appear: super.processTextEvent(te). ( `- [9 n3 {' B; w
  解答:A, B, E ; e' X0 {; H7 V, o- d
  点评:由于类是public,所以文件名必须与之对应,选项A正确。如果不在2、3行之间加上super(nrows,ncols)的话,则会调用无参数构建器TextArea(), 使nrows、ncols信息丢失,故选项B正确。在Java2中,所有的事件处理方法都不返回值,选项C、D错误。选项E正确,因为如果不加super.processTextEvent(te),注册的listener将不会被唤醒。
$ i' n, n! G* ^  1.Which statement about the garbage collection mechanism are true?
' ]' d# M4 m9 q6 }A. Garbage collection require additional programe code in cases where multiple threads are running.   |( K: `5 N4 @( H; I& ], F8 h
B. The programmer can indicate that a reference through a local variable is no longer of interest. + q4 V6 z) ?2 Z: j- ~* K/ z
C. The programmer has a mechanism that explicity and immediately frees the memory used by Java objects. 2 ^" P* n1 y) c( T3 Q$ W: u( j: v
D. The garbage collection mechanism can free the memory used by Java Object at explection time.
3 u8 s% q- p1 {E. The garbage collection system never reclaims memory from objects while are still accessible to running user threads.
( t/ x1 v; o% q+ b& L4 s* _! Z1 d. ]& y: M0 p: p' V
  1。B、E , L# r6 s/ p9 d
JAVA的垃圾回收机制是通过一个后台系统级线程对内存分配情况进行跟踪实现的,对程序员来说是透明的,程序员没有任何方式使无用内存显示的、立即的被释放。而且它是在程序运行期间发生的。
. b- L8 |) Z1 u& a答案B告诉我们程序员可以使一个本地变量失去任何意义,例如给本地变量赋值为“null”;答案E告诉我们在程序运行期间不可能完全释放内存。 # b6 T0 s. v+ C* N: ~0 d
! C6 B  c- _- c. y
2. Give the following method:
4 X0 j5 c# l- r4 o9 C5 B1) public void method( ){ ' t, U" d; _" U" @- U8 ^# J
2) String a,b;
* s* T8 a) u3 T8 ]0 E3) a=new String(“hello world”);
) M, g4 k( {" x4) b=new String(“game over”);
3 d$ V' u5 }1 {8 V6 W: |9 I" B5) System.out.println(a+b+”ok”);
3 h; t" [1 f2 M. c! g  O6) a=null;
6 P1 u7 |7 _& o" h. S1 T7) a=b; ) n0 I/ Z2 {4 n, q; R' U
8) System.out.println(a);
2 K1 L& G4 H' H  U' M9 N9) } 5 ^8 T3 Q& G( s4 s
In the absence of compiler optimization, which is the earliest point the object a refered is definitely elibile to be garbage collection. , x- _9 R; @$ U- k9 Q; i
A. before line 3
, Q! q1 ?8 R! b9 E( j4 P; }& IB.before line 5
- M5 W, o' E+ W5 }C. before line 6
! ^9 I: c4 V2 c* S* C2 X  ]4 `D.before line 7   N: R3 G# }; ~3 s( \0 ?
E. Before line 9 3 a) b' e, ]$ f  x" b5 S% c
  2。D , n! M3 q' M$ W) T& y4 w. H
第6行将null赋值给a以后,a以前保存的引用所指向的内存空间就失去了作用,它可能被释放。所以对象a可能最早被垃圾回收是在第7行以前,故选择D选项。
$ ^" `6 l! G- {8 t. t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?
0 Y8 ~, S9 G& c+ ]A. It is a reference to the object directly affected by the cause of the event. + z5 Q2 m* m+ |
B. It is an indication of the nature of the cause of the event. : R7 S( n  Y  @/ D3 [& w, q
C. It is an indication of the position of the mouse when it caused the event.
& n% r0 h+ k. Y  {) \! E* wD. In the case of a mouse click, it is an indication of the text under the mouse at the time of the event. / V; O: K- O! ^! s
E. It tells the state of certain keys on the keybord at the time of the event. 9 y5 K# ^% d  U
F. It is an indication of the time at which the event occurred.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-15 21:13 , Processed in 0.244035 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表