a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 77|回复: 0

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

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
3。B
( {( V$ e. }- u$ z2 N请查阅JAVA类库。getID方法的返回值是“event type”。在认证考试中,总会有类似的书本以外的知识,这只能靠多实践来增长知识了。   4. Which statement about listener is true? : ?' s% a$ L2 O
A. Most component allow multiple listeners to be added. ; R5 w3 w( q( N3 g: Z" u2 M
B. If multiple listener be add to a single component, the event only affected one listener.
+ |7 r& [  F1 S* O3 |7 ^$ S# ]C. Component don?t allow multiple listeners to be add.
7 M: s$ i: }& ?# K# h* h! W1 s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.
6 X& B3 m% Z* M. j/ Q; I  4。A、D
, o, X8 N3 R1 @( L控件可以同时使用多个“addXxxxListener”方法加入多个监听器。并且当多个监听器加入到同一控件中时,事件可以响应多个监听器,响应是没有固定顺序的。 4 a  y8 h; {7 Z! h8 A
5.Give the following code:
0 x! S! m9 [. h1 w! I  C% Jpublic class Example{ . h: m( Y3 ~9 |% [  c; V
public static void main(String args[] ){ : y6 X/ F8 k7 g6 T
int l=0; 8 D- c4 C1 M' U& L% e$ n7 ~
do{   m! i, n0 e7 z( Q4 @' J: g2 F
System.out.println(“Doing it for l is:”+l);
' L+ p+ s3 L- |! u}while(--l>0)
# N  p( K( v7 P1 ^# e4 G1 vSystem.out.println(“Finish”);
/ F! t$ s  b6 Z3 B} . h1 o+ F+ Q) ?. t# \. A" \1 V
} ( K" m2 y6 |6 U- Z
Which well be output:
) Z  o  z2 _) y; P& o3 U8 K5 Y& YA. Doing it for l is 3
" H( w' d. c  X& {. _# v7 m+ `. f, P# R$ OB. Doing it for l is 1
' m' g% k  Q; i! ~C. Doing it for l is 2 : N! y' k. N% o3 J
D. Doing it for l is 0 : y$ d( E1 u, S( U, f# `8 S
E. Doing it for l is ?C1
( m" z+ t$ F  n* S- \F. Finish
6 l. e1 E+ n5 A' I1 D* V# ]
5 f: Q) m3 }& j9 V  V  5。D、F   m) _8 |) w3 D
本题主要考察考生对流程控制的掌握情况。这是当型循环,条件为真执行,条件为假则退出。循环体至少执行一次,故会输出D。循环体以外的语句总会被执行,故输出F。
# d$ _2 c$ }% u# c$ b3 P( m, ^& d& W  6. Give the code fragment:
6 r4 `) u( m4 W5 S/ D1) switch(x){
& t& M$ {, F% p8 N1 x2) case 1:System.out.println(“Test 1”);break;
# h# h  X7 W" I& k3) case 2: , c; A' |2 X4 \8 T6 I8 x, B
4) case 3:System.out.println(“Test 2”);break;
. x* w5 y% ^6 d% I! K; D/ y. l5) default:System.out.println(“end”);
0 C5 r) F" A4 e1 ]9 J8 V: Q3 Y5 m6) }   v$ K$ ^) @/ h- O1 F! d
which value of x would cause “Test 2” to the output:
  m' D+ D, y) N7 HA. 1
# i3 ]% U  U# NB. 2
/ D2 h# g3 i6 Q5 DC. 3 9 _: Q8 T6 i: @4 z! L+ x6 p0 G
D. default ! h* j% O/ _1 K9 p1 d4 X
  6。B.C
( g; m2 i& [( v9 t. E在开关语句中,标号总是不被当做语句的一部分,标号的作用就是做为条件判断而已,一旦匹配成功,就执行其后的语句,一直遭遇break语句为止。(包括default语句在内)
/ f. I* O4 n- q1 j. K$ |  7. Give incompleted method: 7 p% }5 g) _  F( F# c7 D$ w& ]
1)
+ H, B& o5 [% W) t' L$ ^! R2) { if(unsafe()){//do something…}
1 H3 u; w2 G" \3) else if(safe()){//do the other…}
5 r+ Z- z# ~7 l4) }   k  z5 i9 c, z1 y
The method unsafe() well throe an IOException, which completes the method of declaration when added at line one? : e) J7 e  M" o5 K
A. public IOException methodName()
' B  D) d" _- Q+ N' Q5 O; `B. public void methodName()
* W9 l; ~1 q# U: aC. public void methodName() throw IOException ) |6 s: G8 |$ K3 ~# w9 F. a
D. public void methodName() throws IOException ; ?5 E9 _; Q. V& [
E. public void methodName() throws Exception + d# j0 r0 y2 u( o
  7。D、F
5 x( }4 e" B+ F3 BIOException异常类是Exception的子类。根据多态性的定义,IOException对象也可以被认为是Exception类型。还要注意在方法声明中抛出异常应用关键字“throws”。
% g) t- ^: k' {/ _! P  8. Give the code fragment: 3 q) v+ ]- |; {5 x1 W
if(x>4){
8 H% y) k3 a! lSystem.out.println(“Test 1”);}
7 ?* i) v& ^% M, p3 g  s) s/ Gelse if (x>9){ + q7 h4 H8 P; U9 g. t
System.out.println(“Test 2”);}
4 G) ]" |2 W# Z$ W2 N/ telse {
2 H* j' I) @; z$ jSystem.out.println(“Test 3”);}
" I( {5 j# v2 P6 Y3 x, w) gWhich range of value x would produce of output “Test 2”? , }- r" Z  S6 Y; h8 O
A. x4 + x! ~/ E7 h* U
C. x>9 5 z  d% ~$ N; y: t+ S$ q
D. None & `- G1 }5 C5 o, N/ i8 Z' G) @! R
  8。D
+ H% P# [- h  K2 ]2 p; h% ^只有两种情况:大于4时输出“Test1”,小于等于4时输出“Test3”。 7 R# M% b+ x" G$ ]7 l6 T/ ^
  9. Give the following method:
+ s- T0 @7 C2 Mpublic void example(){
' Q: s3 \( U9 {( {% M* |try{
& r% P, S8 T0 yunsafe();
, s4 b) G9 h9 F- C9 k  N- j; ^System.out.println(“Test1”); 9 I. S+ H; p7 l* J6 V
}catch(SafeException e){System.out.println(“Test 2”);
9 p+ e2 M- L4 ?}finally{System.out.println(“Test 3”);} 9 g1 ?8 t4 G0 S( Z& J- c5 E% w
System.out.println(“Test 4”);
- F8 t! F6 d% \; rWhich will display if method unsafe () run normally? ( t4 V7 P5 K; v) p) \; f
A. Test 1
- j. S$ Z, u( S8 K. ^/ PB. Test 2 $ n9 J8 D) \1 h$ |4 R
C. Test 3 6 l7 [" C* H) r# b% ~
D. Test 4 3 J/ k' o- r8 n2 C
  9。A、C、D
6 d2 O, S( G, J5 k在正常情况下,打印Test1、Test3、Test4;在产生可捕获异常时打印Test2、Test3、Test4;在产生不可捕获异常时,打印Test3,然后终止程序。注意finally后面的语句总是被执行。 1 O/ A- F6 C# c' M' g- N
  10. Which method you define as the starting point of new thread in a class from which new the thread can be excution?
, M% M5 Z" z) i( jA. public void start()
2 O' m  P; @; x/ [8 N. N2 GB. public void run()
/ Q, }3 q$ e( T3 zC. public void int()
' o$ D" s! c# eD. public static void main(String args[])
2 Y# g/ `9 L) }% O: qE. public void runnable() 3 O" |5 N3 z; t9 I9 l3 ]
/ t" X" ]5 |1 I9 k, i- ~
  10。B
3 Q+ Y6 G: F/ C  H线程的执行是从方法“run( )”开始的,该方法是由系统调用的。程序员手工调用方法start(),使线程变为可运行状态
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-15 16:24 , Processed in 0.224439 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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