设为首页收藏本站联系我们

JAVA中文站

 找回密码
 注册会员

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
JSP虚拟主机本站QQ群:36839023广告位招租JSP空间
查看: 6427|回复: 0

SCJP考试题310-025(第一套)

[复制链接]

该用户从未签到

发表于 2009-1-4 14:18:59 | 显示全部楼层 |阅读模式
这是SCJP的考试原题,是1999-2000期间的!提供给想考SCJP的参考!. e4 h. m& E: b% j8 B# e+ \
    我这还有其他的一些,如果全部打印可能100多页(双面)的样子!我将陆续的在这里粘贴出来!(如果可以的话),一共分为几套!这第一套只有19题,其他的几套有点多,300多题的都有,我归纳的,我同事说看完了它,考试就没问题,所以我就搜集了这么多,我也看的头大,所以发出来给大伙分享,敬请关注!!+ H9 c3 X- Z/ z, E: S$ n
1. Which statement are characteristics of the >> and >>> operators.
& f  Q. K4 c8 \( K* B* CA. >> performs a shift/ U0 d) m5 E. p& `
B. >> performs a rotate- L: m+ U( y$ a$ A4 h7 O
C. >> performs a signed and >>> performs an unsigned shift
) T2 x8 |$ s8 bD. >> performs an unsigned and >>> performs a signed shift* E" }9 z9 ^2 M
E. >> should be used on integrals and >>> should be used on floating
2 a3 K- J# |# v# }% {point types
  k7 w7 g$ O& OC.
) U: ]% P& a) @* ^$ K" v3 D8 H2. Given the following declaration3 h$ @4 d2 q' C% E' ?1 x" o
String s = "Example";9 l  f% Q% C! U" |4 w5 Q0 `9 j
Which are legal code?, G& o# P" f  u0 T  ~4 O$ I
A. s >>> = 3;1 h8 r7 m! ^0 t+ T& D6 q
B. s[3] = "x";* C8 ~) g0 u5 S( r1 ^! n/ v
C. int i = s.length();
2 Z3 |. w; c  N8 l, f1 p# ?D. String t = "For " + s;# O! i" @9 o$ @( J+ l) H3 @
E. s = s + 10;# H* |$ g6 K4 X# S. a
CDE.; h2 N$ v+ b5 ~( |6 f, N& `* @
3. Given the following declaration* Y0 W! t" p* v/ [" r) i
String s = "hello";
; S7 G' R! d9 n; i) j( wWhich are legal code?: s- a! {5 u% O" x& n
A. s >> = 2;
$ _1 I& ?, \) i; d& q. [7 K2 aB. char c = s[3];
( U# T" k: a9 P! OC. s += "there";
- a! E# q' @0 T4 kD. int i = s.length();2 n% ^( E' z) p; \0 i, A
E. s = s + 3;
4 S- p1 w" o2 }4 w8 RCDE.# ?* x  Z) }; D$ f
4. Which statements are true about listeners?
* M# r6 W! `+ f/ tA. The return value from a listener is of boolean type.1 Y/ g6 `2 K# R
B. Most components allow multiple listeners to be added.
) B3 O+ `' [/ r/ p3 H& ]! SC. A copy of the original event is passed into a listener method.
& h8 f% k% A9 s, n9 \0 p+ j6 FD. If multiple listeners are added to a single component, they all must, P- y+ T5 E3 Z3 L
all be friends to each other.7 I& G6 |5 g' N) ^! L' m
E. If the multiple listeners are added to a single component, the order. ?" r: g9 G, h3 G
[in which listeners are called is guaranteed].1 H+ o% `0 ~8 H# d* Z3 N( U7 ^$ ^
BC.' i) h7 U8 H4 X) ~
5. What might cause the current thread to stop executing." ~, ?/ T6 B  {; e! x$ E9 a' `6 o
A. An InterruptedException is thrown.0 s9 h. ?0 E* q: F
B. The thread executes a wait() call.# U/ K3 Y* E' u5 \- d$ T
C. The thread constructs a new Thread.
9 z9 z* P! c+ ~  q; z$ RD. A thread of higher priority becomes ready.( W% L6 X4 P* d0 R- l
E. The thread executes a waitforID() call on a MediaTracker.# X; n4 p4 C: t6 h  `9 O
ABDE.
4 Y% c7 s$ Q/ `/ o/ O. k% S4 M6. Given the following incomplete method.
+ a, U7 ?4 _9 ]; ~5 x! E' L) f1. public void method(){! ~/ m* `) H/ |& D
2.# J; p' Y5 a) Z1 c* d
3. if (someTestFails()){/ h9 d" p* S3 h# e
4.
8 y( S+ R8 [, T) \+ O$ j7 L' a  {7 k5. }/ i* v9 l  f. K& x+ K4 l
6.; p7 g5 d. f1 z, D! `
7.}7 t' G2 j1 n/ F* F5 }
You want to make this method throw an IOException if, and only if, the/ u: o5 y# t$ |+ u' _- d, L/ c# ], U
method someTestFails() returns a value of true.
# W0 d! V5 Z& G3 A8 G) ~Which changes achieve this?2 C8 P  g: ^+ y; l4 m
A. Add at line 2: IOException e;' ~4 x6 s( h$ G! [8 N8 U" L. K
B. Add at line 4: throw e;
. K; _5 M# g7 N% Z$ k/ I: l3 h3 ~9 rC. Add at line 4: throw new IOException();- C: P$ |6 E/ p$ b( u# H
D. Add at line 6: throw new IOException();
$ Q/ S2 r( P8 ~. g2 D) K7 A. W0 DE. Modify the method declaration to indicate that an object of [type]
6 z  ^' ~3 q4 q. H/ ?' uException might be thrown.
6 r; i4 Y, \! z, j' i2 d  e# V8 sCE.& I8 m  C; e: h
7. Which modifier should be applied to a method for the lock of the
( ~) P' E2 g6 w3 E6 D- ]! X9 z" {  R  Aobject this to be obtained prior to executing any of the method body?
9 z  t) |& B, q/ H* D! VA. final0 h3 m& b' F: b6 @
B. static
6 [3 p# G7 }: H! u; @/ I/ K3 VC. abstract1 R7 {2 K! K4 ~) l. J5 i
D. protected/ l5 z2 X1 [) K$ Y9 P4 a
E. synchronized
4 v" C# h0 j* A1 uE.
7 [* @4 e8 G1 `8. Which are keywords in Java?
# b! x' S6 c8 D3 W/ v; cA. NULL9 g. w% Y( f# v  s$ N$ N/ v' j
B. true  R+ r% Z6 h1 W% P$ @2 x: B: ^* q1 `
C. sizeof" ^) p2 S' S- D9 m; w( p8 A1 y
D. implements( j. g5 u4 c' l2 n0 f6 l
E. instanceof' M7 J7 [! i/ |. F3 r
DE.
1 J  _" v# D% x9. Consider the following code:
1 n3 v! t- D8 }: pInteger s = new Integer(9);
5 l- W6 c. w7 H* W, T  AInteger t = new Integer(9);& h5 x+ F, s0 F. U
Long u = new Long(9);9 ?6 m" G5 F) T" m) i. d
Which test would return true?
) L5 o; W' F* U2 PA. (s==u)4 y) x6 }- S; I: r% W
B. (s==t), n3 F9 u! \/ ?9 Q2 g
C. (s.equals(t))' W2 C$ \* G4 \) S( B
D. (s.equals(9))
2 s4 a) `9 e1 i- pE. (s.equals(new Integer(9))4 W6 F5 q+ }, |5 ^) M  k/ N) |9 K9 a
CE.
% z+ K# B8 `+ N5 S9 W; y4 K8 I- R10. Why would a responsible Java programmer want to use a nested class?" Z7 [' X4 t# E0 v$ J+ M+ {. z4 D
A. To keep the code for a very specialized class in close association
1 u6 ]1 a* n( ^; J6 `, s, hwith the class it works with.
$ ]* n8 N+ g; G, u( tB. To support a new user interface that generates custom events.
* v- j  S0 A6 X- q8 ?8 T- iC. To impress the boss with his/her knowledge of Java by using nested
* o0 o! P5 _8 }6 S) K: Gclasses all over the place.+ @0 d4 i5 h( x- `, _8 ~! ?1 V
AB.
3 H9 O! [9 e; W! L' C: p/ p" g11. You have the following code. Which numbers will cause "Test2" to be
! @! A. Q$ w$ ^# f1 bprinted?
9 c# [3 z8 D* y3 Cswitch(x){
3 [* ?% ]: B" H7 u/ i2 j. ~5 ?+ jcase 1:
: r( C8 y7 N$ h3 f7 N+ _+ t" p1 l- ?System.out.println("Test1");' \/ P: l! _( n3 R- W* t) b( n
case 2:
$ o( y  ?4 a8 bcase 3:7 c5 m' C" ~  \- p; P* J- Q9 T: `
System.out.println("Test2");
% G6 `, O8 h. m! y6 j+ ~, |break;
  P* O# T! t! ?4 J5 ^. @}
/ M" |) M3 G( `7 U0 {, YSystem.out.println("Test3");
+ m  b/ P+ ?" {+ Z; d/ O}
8 ~7 O; u. |& l1 Z# M( P& I/ G1 S3 pA. 0( X$ V: H8 ]. m
B. 1& j+ B- Q5 ?- D) P, f& w
C. 2. F* Y. I+ P9 Z' d. i6 _8 ?
D. 3
/ f0 j. H: H" r2 o6 y# E2 IE. 4
' T" c, M, \( o  W. ?BCD.) G) p4 R$ W& r2 |% |
12. Which statement declares a variable a which is suitable for
/ ~. M9 V) r% b" Dreferring to an array of 50 string objects?
- ?' M( e& b8 Y! l; |( d- Z4 @A. char a[][];
( v+ [$ b* O; T  P; oB. String a[];1 Y) q2 m* h0 b2 i
C. String []a;' \$ C/ a0 T; C1 C  `. d/ a
D. Object a[50];
% a& e3 y, B3 T1 e8 DE. String a[50];! W: Q6 ^* e6 N' r/ {' v1 {2 L
F. Object a[];
& ?* S* D+ s; g! R  `  @BCF.8 R7 H  q! c& {) V/ B& a8 V& i+ e
13. What should you use to position a Button within an application
6 s. E7 w, j7 F/ _. D+ n: I& k% z3 ?frame so that the width of the Button is affected by the Frame size but. I/ L8 H' ]" `/ [) k+ s
the height is not affected.
$ V7 H1 Z6 b% L# `6 GA. FlowLayout
, y3 v9 B& u' j% L/ w. u2 ^# g" SB. GridLayout6 r  S8 b; Z8 s9 z
C. Center area of a BorderLayout
0 u' P$ q2 u- ?5 c; c8 JD. East or West of a BorderLayout  L: R( y/ D( F" \# e7 ?0 T
E. North or South of a BorderLayout9 `% W: i3 K7 ?* v2 o0 D
E.
- A/ |1 M8 Y  S. I; O( f14. What might cause the current thread to stop executing?/ B1 q6 v/ f  e
A. An InterruptedException is thrown
( I$ D$ w: `1 O% R# Y5 eB. The thread executes a sleep() call3 i: }3 r# B6 ~" P# Q: ~+ x- z
C. The thread constructs a new Thread% a7 K4 Z3 |) j
D. A thread of higher priority becomes ready (runnable)8 J1 A# N4 p0 g6 L- q
E. The thread executes a read() call on an InputStream! r6 d; v, v& _! q: N: b
ABDE.; B, O- y; b; D$ `0 G% u! r0 D% Y
Non-runnable states:7 ?3 r! X' l0 @# t( I) U  J; M
* Suspended: caused by suspend(), waits for resume()
1 q# H0 j* s: ?) p' T3 }# D* Sleeping: caused by sleep(), waits for timeout
4 w" V0 W' R. \+ L1 r+ _* Blocked: caused by various I/O calls or by failing to get a monitor's5 X. s4 w9 \5 U! e; J& J# p/ z
lock, waits for I/O or for the monitor's lock
1 ]9 K' U: h8 u6 y- `* Waiting: caused by wait(), waits for notify() or notifyAll()
' T1 W& P7 U* x  X$ `3 h* Dead: Caused by stop() or returning from run(), no way out& `+ g4 w4 e5 P/ o1 q
15. Consider the following code:4 _" z4 f5 z  p, Q8 Y( B5 L
String s = null;3 [: o. R# M% _2 y# p
Which code fragments cause an object of type NullPointerException to be
& G  H* ~1 Q; k: A( t2 S/ T' Ithrown?
# A$ r. \6 K* [A. if((s!=null) & (s.length()>0))8 W+ E# ]/ {  Z& Y% p1 k1 c
B. if((s!=null) &&(s.length()>0))
8 `  \* z# n% dC. if((s==null) | (s.length()==0))
* U7 {3 ?9 c( _D. if((s==null) || (s.length()==0))
% X7 s0 N# _6 s) hAC.8 N# j. |3 j- F) c0 o
16. Given the following method body:6 [0 J4 C: ?5 [5 I4 @4 P
{- ~( C4 ?" q' Z/ O; o  R2 _
if (sometest()) {7 ~, {- d# i+ ^: O3 o; T' y8 v
unsafe();
1 p! T, ]& V5 u# M}
4 \9 x3 H& P: u- h, y, h& R  melse {6 I% K6 q) r# X& N5 F' d& z
safe();2 X- u6 Y; p7 a- ]7 Q1 b+ K+ `$ v
}3 \$ j7 m, _: J" F. V  U
}
0 D8 r: S0 x5 h( |- H9 ?The method "unsafe" might throw an IOException (which is not a subclass; y; Q* K2 A9 C# p7 ]) K! ~
of RunTimeException). Which correctly completes the method of$ p& {* {% Z+ i' A7 r+ @& j- a
declaration when added at line one?
( B' c: q; Q2 z" aA. public void methodName() throws Exception
4 u. N! Y" O) Y, c. ?B. public void methodname()
  B0 W0 x7 V9 @. b3 A5 D; z+ o! gC. public void methodName() throw IOException: m9 c$ x9 E5 h" v
D. public void methodName() throws IOException
/ g9 ]+ j! Z. T; Q5 X) A2 IE. public IOException methodName()
3 V$ K" K7 ]2 {AD./ ]2 U% M* U' a& A
17. What would be the result of attempting to compile and run the. ]- {- v9 W" J& F7 ?3 d; I5 V* v+ A
following piece of code?
4 A# h  F( Z4 n; [8 G9 f$ R: @public class Test {& Q, x& t$ X8 i* C% ^' J, G( T+ V
static int x;
; A# ~/ |0 O, F3 N  Opublic static void main(String args[]){# R; ~. I. v' n; W$ ^
System.out.println("Value is " + x);& C8 ^0 \' t, n9 R& B+ `! a1 r
}
/ n# W9 _& B! z- `}
9 K! g+ M: ]4 G; t2 p- a2 YA. The output "Value is 0" is printed.
, B4 O0 S% L# ~; b/ M/ b* b% Q- rB. An object of type NullPointerException is thrown.
- w+ a& ~/ v9 c- ]7 C. tC. An "illegal array declaration syntax" compiler error occurs.
- l( k/ M# X5 I7 S% SD. A "possible reference before assignment" compiler error occurs.
* T/ k2 K8 j3 h* [" h  t% V$ rE. An object of type ArrayIndexOutOfBoundsException is thrown.7 @9 @' ~' v6 b# F3 h, D
A.* o- |0 f! t! M
18. What would be the result of attempting to compile and run the
' k2 Q8 D7 G1 L/ P+ ^* T3 P" Lfollowing piece of code?7 X! \; E" U. Y6 z* Q
public class Test {% y, O  n- W$ d
public int x;
  ]' r' K0 _/ Y& Opublic static void main(String args[]){
3 G9 J, Q# w- R0 C8 [System.out.println("Value is " + x);
- p2 a. ]/ D, \9 w  A+ T}! R6 u3 f& m( R+ h: G. F! t3 ?
}
0 O( E- ^. @- U" l4 W/ n8 HA. The output "Value is 0" is printed.2 W/ ?) y- E4 T8 p# U: f( Z
B. Non-static variable x cannot be referenced from a static context..
6 t( ^( U& I9 |. b! F  DC. An "illegal array declaration syntax" compiler error occurs.0 u) o% T" x7 V1 a
D. A "possible reference before assignment" compiler error occurs.9 j) B2 l, A2 }% A6 k6 e
E. An object of type ArrayIndexOutOfBoundsException is thrown.0 D3 Z; t2 n5 O8 k8 _- s3 B
B.
# d) Y9 A. ]" T  t6 r: e, O$ `0 Y19. What would be the result of attempting to compile and run the/ [4 ]' }) @5 J7 ^# p" ]& n
following piece of code?
7 [: `& j/ c0 {0 Q. G  \, qpublic class Test {% M% L2 M$ E- ]% X- X$ I
public static void main(String args[]){  H( v, q% e3 E5 k, W
int x;
  Y/ C3 g. {0 O2 qSystem.out.println("Value is " + x);9 W0 o4 p7 y4 B; `! y5 N5 L" k
}
3 |/ }# P, c' |}
6 q; C8 e8 V9 v7 \5 b- yA. The output "Value is 0" is printed.
- w) }+ i+ Z+ {/ \) ^B. An object of type NullPointerException is thrown.
! Z3 l& g# X0 D; \C. An "illegal array declaration syntax" compiler error occurs.
, r) }8 |( \* e/ x3 P; a. _D. A "possible reference before assignment" compiler error occurs.
. g3 R. f; T) e0 a- YE. An object of type ArrayIndexOutOfBoundsException is thrown.( _  ?5 [, U; s$ C
D.
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|小黑屋|手机版|Archiver|联系我们|JAVA中文站 ( 浙ICP备12034637  

GMT+8, 2018-6-15 14:02 , Processed in 0.564714 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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