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

JAVA中文站

 找回密码
 注册会员

QQ登录

只需一步,快速开始

扫一扫,访问微社区

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

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

[复制链接]

该用户从未签到

发表于 2009-1-4 14:18:59 | 显示全部楼层 |阅读模式
这是SCJP的考试原题,是1999-2000期间的!提供给想考SCJP的参考!
. `, s! [+ o. v! n( e9 q    我这还有其他的一些,如果全部打印可能100多页(双面)的样子!我将陆续的在这里粘贴出来!(如果可以的话),一共分为几套!这第一套只有19题,其他的几套有点多,300多题的都有,我归纳的,我同事说看完了它,考试就没问题,所以我就搜集了这么多,我也看的头大,所以发出来给大伙分享,敬请关注!!
* m- x& u7 z' S4 p1. Which statement are characteristics of the >> and >>> operators.
; q4 L6 z3 Q7 q4 Y0 BA. >> performs a shift
3 R7 x3 e! S. v4 O* ]6 ~' l1 WB. >> performs a rotate
; e9 E4 q; }4 c' A- o  g+ S# KC. >> performs a signed and >>> performs an unsigned shift
9 N( r7 L  o! [& F3 kD. >> performs an unsigned and >>> performs a signed shift
: f( P$ H, e% z- mE. >> should be used on integrals and >>> should be used on floating
, N: }+ n# k5 X+ O( L4 zpoint types
& {7 r2 w9 n: f$ {; h' z. ^6 rC.3 f% @  U) p% r0 [, H4 s  [
2. Given the following declaration
5 t3 r- O( h$ |: w1 k* ]String s = "Example";5 z, n& J( T9 P* r2 y2 _, {  g
Which are legal code?) f/ s& Q# f0 L
A. s >>> = 3;. F# H. n" M  T/ P/ i+ T& O6 t0 y
B. s[3] = "x";9 w4 O& D: Y, b( j! }+ S% `
C. int i = s.length();
# t9 \7 H* g( d8 h8 XD. String t = "For " + s;
, F" `: ^$ n* E; D& L5 ^E. s = s + 10;" r$ s8 w- H5 ]+ X% ]$ S/ i" S
CDE.: ^2 y& R# h. l3 ^
3. Given the following declaration
$ r% A& h* J% c$ I+ GString s = "hello";
/ @+ D) c" R, m/ D: W$ KWhich are legal code?4 C2 Z: z, t3 a; c  L4 n
A. s >> = 2;; I0 o$ r) T$ d3 @% K/ T: b0 g
B. char c = s[3];
4 S% `% s/ x. C! i2 d  `3 [C. s += "there";+ @3 H& s- x3 X' B  B# `4 U
D. int i = s.length();& p( Z+ ]0 y8 S' b1 C8 `( }$ z7 K
E. s = s + 3;
/ q( Z" W7 \; WCDE.2 `6 c3 ^" C; {% C  x% N' }6 h2 G, W  D, P1 V
4. Which statements are true about listeners?
2 F+ Z( m! m, l' Z! C! t5 c  oA. The return value from a listener is of boolean type.
" `9 T3 H& }# M2 g) t8 jB. Most components allow multiple listeners to be added.
$ g" \# V# `1 I; y- HC. A copy of the original event is passed into a listener method.1 y1 Y# Z' X3 A6 [% p& U: |: c
D. If multiple listeners are added to a single component, they all must$ w& C3 c3 _' o; h+ `
all be friends to each other.
- A/ u9 c% M& {3 m" yE. If the multiple listeners are added to a single component, the order
0 @" ]: C9 \' E' b8 [3 Y[in which listeners are called is guaranteed].$ y( r2 @1 m) H6 B0 L
BC.
5 @% k- k* _- v5. What might cause the current thread to stop executing., ^, o2 v# v2 _2 ^( t, n" b4 E( r9 C
A. An InterruptedException is thrown.
9 I; `( G" j( b& z1 \+ ?' q9 |B. The thread executes a wait() call.: \) i6 N! ?0 k' R8 V- T2 k! _
C. The thread constructs a new Thread.
1 M2 u/ p; M9 ^, I& U: e: mD. A thread of higher priority becomes ready.0 N+ `( {  W2 j! T5 ~2 q: q
E. The thread executes a waitforID() call on a MediaTracker.' {8 p2 @/ L1 y& ?8 Z! M
ABDE./ e- X6 n7 i; A4 x. w: S8 J
6. Given the following incomplete method.
! r5 K4 K5 N$ Q( s+ Y2 B1. public void method(){+ @$ T7 F) V" x; S  x, w9 A, z
2.
4 ^  y6 r& H6 p5 i! I- s5 t3. if (someTestFails()){* J# Z  x, b3 j. I5 e  |& \) N- H6 J
4.. y8 @$ a) m* [5 l' J2 E
5. }
% o4 J6 Z, y/ ]2 d1 Z( P" K6.2 i. h- q. O2 {# u
7.}' t) i  Y6 O- P) {' J% M8 x! l) g# `
You want to make this method throw an IOException if, and only if, the
; F" B7 G6 O" mmethod someTestFails() returns a value of true.9 `  b4 j- h. _
Which changes achieve this?
% f2 M- z2 ^$ b1 P9 C( D7 C( CA. Add at line 2: IOException e;6 C4 }% b5 K8 `6 [
B. Add at line 4: throw e;, O: L( |& H/ `; Y9 k6 ?/ P3 E/ l
C. Add at line 4: throw new IOException();
) W" a) [3 b6 Q7 }( |- jD. Add at line 6: throw new IOException();
0 d" P- ?0 S6 G+ G5 ^" |. ^+ oE. Modify the method declaration to indicate that an object of [type]$ ^; x5 @3 a, i6 w! `$ B9 y
Exception might be thrown.* E9 w" H3 V5 u5 I
CE.8 E2 y5 Z0 ~* N. N: N
7. Which modifier should be applied to a method for the lock of the
. q! ~& B4 ]' yobject this to be obtained prior to executing any of the method body?2 d0 ^8 V. S- _  s. d7 j( c; n, c
A. final
  w; W7 M( y9 k  X  L2 H. PB. static
, ^6 Y! `2 w( u; m" [) ]1 Z- FC. abstract  }% r+ `5 ~+ o  ]8 x+ e
D. protected
, _1 x7 B* @( @" eE. synchronized
% M: R# W1 y) d( y$ m% vE.9 ~4 C# t; X' Y0 `# k2 u
8. Which are keywords in Java?. Q0 [+ i! [5 b3 e
A. NULL
( J+ ?' w: A& ^* fB. true
% Z* Z1 O; t. \+ y# iC. sizeof
7 i# Q  ~3 z7 a* |' ]9 `9 M+ fD. implements& q) `3 k0 q, P$ E0 b0 o& ]5 t
E. instanceof; ?$ Y) }4 i' U
DE.5 Y: v. @( p- u
9. Consider the following code:" l2 ~- D# ^6 E' v8 x9 p6 \4 S, p
Integer s = new Integer(9);
4 x$ b  C9 _( NInteger t = new Integer(9);
, r6 g) G# ]4 X1 q# o$ ?Long u = new Long(9);
: ?1 A8 C9 s0 ?9 Z' gWhich test would return true?/ c% u7 _# F8 m7 T8 ?! j$ B
A. (s==u)
- I) g# I/ Z# u$ k: u# [9 g: h0 w- uB. (s==t). P  J+ w3 u  F9 K6 d% f0 }. q
C. (s.equals(t))1 u% A3 q9 {' i  S  F% A5 k
D. (s.equals(9)); {8 h  I7 |2 ?/ c
E. (s.equals(new Integer(9))6 [' r4 h$ H' k: c- W, W( O! ?8 W: Z
CE.
9 l. ~8 C& V% Y6 C( m# g& N4 \! T/ _( Q10. Why would a responsible Java programmer want to use a nested class?
* b# w% ?/ b! Z! r5 s) TA. To keep the code for a very specialized class in close association
1 j! @+ X% O4 y, ]( A& k$ Ywith the class it works with.0 Q. [. \( b& W9 o7 z1 Y
B. To support a new user interface that generates custom events.
: K- J0 c/ f7 f6 I8 }C. To impress the boss with his/her knowledge of Java by using nested$ t3 @% V* l& V! H& {$ ]( w) U6 G
classes all over the place.
' A. D. o7 z; Y5 c6 S3 Z7 iAB.
0 }! ?" w8 y, {* g, l) |11. You have the following code. Which numbers will cause "Test2" to be
: L* w/ D& K8 Uprinted?* ~* y7 u1 \" q: ]# I/ _' J
switch(x){
0 `: C' }! O6 W3 L3 Pcase 1:
  M" f" E. O9 X! v. o9 CSystem.out.println("Test1");( y4 y  R/ N4 n- G" D5 r, H! E) f: n
case 2:4 \6 b# O" h! V( G3 c
case 3:
/ m, v, Z% E: W' A9 w; @System.out.println("Test2");
' j. v0 X5 M. }. Hbreak;8 |; S% j; U! s- n+ h
}
3 g- D6 n' @& s0 ^7 S; Z- `System.out.println("Test3");# P2 C+ ?" j6 w, M' I
}- [8 @; }0 V( b
A. 03 f- f+ O3 c* P) j, ^
B. 1
! M  y% x% z# H8 ^/ dC. 2
' a9 `3 x/ g- e# mD. 3( n2 @8 y7 r0 w( R! c
E. 4
+ d) Z5 P' T" v2 iBCD.* J* p3 E6 w4 L8 z" h
12. Which statement declares a variable a which is suitable for
& S5 y& X- b- @, Treferring to an array of 50 string objects?& w0 }/ l) z# P& b
A. char a[][];
8 |, X* H: ]$ e2 K' r2 S1 c/ {B. String a[];5 l  O4 d5 b+ z7 m2 U+ B
C. String []a;
4 z; q, }1 \3 G# N3 J- Q" x; i4 pD. Object a[50];
2 b3 r8 h9 w4 j: jE. String a[50];
* k) }, s$ F/ Y- QF. Object a[];
+ y$ L0 N- ^% A' QBCF.
2 B" _" B# Z; L. G  a13. What should you use to position a Button within an application0 k, J4 c  k( ?; v
frame so that the width of the Button is affected by the Frame size but
1 ^. B( E7 T; h& Xthe height is not affected.
" D1 E4 P: k' ]5 J2 oA. FlowLayout
0 u' }( U2 ^: s  AB. GridLayout  ~4 d* T5 A( [$ L& v8 ^
C. Center area of a BorderLayout1 q- H. j. i7 \: b/ w7 e4 h3 P
D. East or West of a BorderLayout
0 ?: }( f1 ^) x# }3 Y$ o5 eE. North or South of a BorderLayout
' {' q8 e) T$ _7 GE." |9 z8 j$ U5 _+ Z, I
14. What might cause the current thread to stop executing?
0 U. p4 Z/ @  G) [- A7 ~A. An InterruptedException is thrown. Z' l7 F5 |5 q3 V$ B; R/ x; A
B. The thread executes a sleep() call
( t5 m- d2 C* \( o: E: k7 PC. The thread constructs a new Thread0 f* T" B& e8 Z* I
D. A thread of higher priority becomes ready (runnable)
0 A# O% J% q0 M8 K4 ?2 l, NE. The thread executes a read() call on an InputStream
* @! S+ ?6 w& [ABDE.& E8 Z0 C* ]) x+ h* _9 ~  b0 ]! W
Non-runnable states:
# d/ B0 X2 m$ N9 X) n, T& h, U% H: n3 p* Suspended: caused by suspend(), waits for resume()
1 B) ~" O- F5 J$ [1 H* Sleeping: caused by sleep(), waits for timeout
* _( f' q9 _) y) i+ Y4 _* Blocked: caused by various I/O calls or by failing to get a monitor's9 h0 i  M9 _) r8 N7 H4 x$ V1 n
lock, waits for I/O or for the monitor's lock
7 A- x# t; y" q" V' o0 }* Waiting: caused by wait(), waits for notify() or notifyAll()  |. _/ H- M$ c: h  [
* Dead: Caused by stop() or returning from run(), no way out
. M0 C, H3 ~7 G( Y) C15. Consider the following code:0 E) H% S3 P2 U6 u
String s = null;! q/ [' D7 e- k9 w# e) Z: u* {
Which code fragments cause an object of type NullPointerException to be
3 i3 p$ I/ U! P' w1 Ythrown?! X0 Q' i3 k" }4 J3 o
A. if((s!=null) & (s.length()>0))7 J; X) {& g  z
B. if((s!=null) &&(s.length()>0))
8 F$ J! I2 z2 }C. if((s==null) | (s.length()==0))# c! m/ q6 T+ Z% o
D. if((s==null) || (s.length()==0))
5 w* f1 O+ D" a6 d) B  V5 L$ {AC.
* `$ Q" f8 Q& B! {* F8 p16. Given the following method body:
, s( f$ P5 _3 ~5 R! T# A+ y: F{
; q$ t# T) M' j. |7 rif (sometest()) {- F% n: \$ p+ o
unsafe();2 [$ Z+ i  _/ ^' p; p  P
}
: Y1 E0 A# ^/ D% X0 I! Celse {
3 j. ]8 j9 i$ A/ W: c$ S6 Vsafe();( F$ U6 }5 m6 f% @+ C6 k! r. a
}
2 `1 v$ {; O) K0 y  Z}
  i; N6 C+ b. b/ N, O, R6 uThe method "unsafe" might throw an IOException (which is not a subclass
' @$ ]6 I# R* s% a- }8 {! Q+ m2 pof RunTimeException). Which correctly completes the method of
8 ^0 g+ b9 C$ Z5 kdeclaration when added at line one?1 [: Z$ Y) P! T" g% W+ Y' F2 s
A. public void methodName() throws Exception% g0 X4 X! P% p1 z+ _+ x# j9 r
B. public void methodname()
3 p  Y9 b6 o/ \. ]( qC. public void methodName() throw IOException0 c8 L7 o  p- D7 T, Y1 [& N
D. public void methodName() throws IOException
& N/ v2 h! Z  KE. public IOException methodName()" e( i5 k. q* v) d; {
AD.
9 @, E9 q! H7 Q) {17. What would be the result of attempting to compile and run the
; Y& l' f% c9 efollowing piece of code?9 [6 b- T$ `4 [2 p9 N; [
public class Test {
3 ~0 T- F7 W* h3 ?- w0 bstatic int x;
0 h4 e6 k* p, S0 R4 A/ Rpublic static void main(String args[]){
# Y# O9 S7 E1 {. d1 z! f& gSystem.out.println("Value is " + x);% u2 h' O7 y1 O  H
}
* k8 h/ R: _7 B1 L}1 K' o' x/ R; ?+ l' L3 C' z3 N
A. The output "Value is 0" is printed.6 Z4 k2 s. x  D
B. An object of type NullPointerException is thrown.+ R3 h$ `2 F2 K: u
C. An "illegal array declaration syntax" compiler error occurs.0 P1 j# u. l: Y* q8 B9 F' T
D. A "possible reference before assignment" compiler error occurs.7 x- O' |' I4 D& ]/ |
E. An object of type ArrayIndexOutOfBoundsException is thrown.
* B* \& x0 r4 E1 ^5 o7 L% wA.3 Z5 j7 D) o" T7 I4 {+ Q- M
18. What would be the result of attempting to compile and run the
7 {1 ]2 \( B2 Y6 @0 b8 Jfollowing piece of code?. r$ S* [' C& r% y# o: F: r; n
public class Test {
/ R) @! v$ }( H* ppublic int x;
* f& }9 {: N* X$ ]public static void main(String args[]){
+ `) J; s5 u0 M$ {System.out.println("Value is " + x);
7 x; X( Y9 u5 [7 _5 C6 U}
% d) |* l. v3 T}' w3 Q9 C3 R* F3 d3 C$ B+ ?
A. The output "Value is 0" is printed.
$ y' q+ |7 ?+ s( n+ k; J1 O4 w/ IB. Non-static variable x cannot be referenced from a static context..
3 S4 Z# u5 j4 T! {C. An "illegal array declaration syntax" compiler error occurs.
# K# X2 {, Q- V( KD. A "possible reference before assignment" compiler error occurs.$ y& g% N: j9 ~  K
E. An object of type ArrayIndexOutOfBoundsException is thrown.: w' W2 l# @( ]: C0 q( _
B.. a" g+ {) Q" f/ t
19. What would be the result of attempting to compile and run the4 K6 |; D2 r% `  P
following piece of code?
' B% A; h) d0 ?# P* L& q) Q: t' p) cpublic class Test {* [: n$ T- X: L1 y( Z0 Z5 v
public static void main(String args[]){
5 e. d6 P0 }8 T' i% E! Rint x;
% H0 _5 @: e# l; T8 u  J1 }System.out.println("Value is " + x);
( W- [% e8 H7 u; a* W# Q! e}, V/ P  \2 H* |; g* y
}& b# _3 v4 q) O* J9 b/ f8 z
A. The output "Value is 0" is printed.
: E& ~1 y6 [; j; {4 ]B. An object of type NullPointerException is thrown.
' L3 f  S. s9 z. rC. An "illegal array declaration syntax" compiler error occurs.9 f" w- J4 {! T: Q% x
D. A "possible reference before assignment" compiler error occurs.
% v- ~) h: K" Z1 A+ |E. An object of type ArrayIndexOutOfBoundsException is thrown.0 E9 @4 m* Z$ M  p9 S
D.
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

GMT+8, 2018-4-10 04:53 , Processed in 0.492873 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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