知道美河 | 上传资料 | VIP申请 | 精品课程 | 资料搜索 | 问题反馈 | 会员手册 | 积分消费 | 积分充值 | 帐号保护
美河学习学习在线赞助VIP

美河学习在线(主站) eimhe.com

 找回密码
 建立账号
查看: 30862|回复: 6

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题
. \  ^) Y/ |. e& M( k/ ]1.        给出以下程序:
, I$ K8 N" E3 U4 ]2 [1. public class Colors {+ H4 Y8 s* b% d! z/ c  m
2. public static void main(String args[]) {
! L, s  I) |/ M( H) o3. int n = 1;( l8 B0 c; t5 R9 [0 W
4. System.out.println("The Color is " + args[n]);/ a; {: m4 U$ l# f
5. }, M  _6 k8 n9 ]  e0 H* I: m6 [
6. }+ t, `* E  P& \6 E2 d
假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”+ a2 n0 L1 b! ~/ E
A.        Colors red green blue yellow8 K  z3 F- ~( I4 ~; c$ J+ |6 x
B.        java Colors blue green red yellow8 V. s2 [% m* Q1 L. y% \
C.        java Colors green blue red yellow( A% \. j/ J0 D( n: }
D.        java Colors.class blue green red yellow
5 s; ?: V. X  i: h6 PE.        java Colors.class green blue red yellow: F, n- ~4 U; G9 \0 F4 ^9 y
2.        读程序:
, ^3 I$ u* O5 i4 f. m1. public class Test{* i% o' v$ ^5 w+ S* u. G
2. public static void main(String args[]){
# {( x; l. _$ G3. char c = '\u0009';
$ H8 J' w0 l% |  v' M7 J- b4. if( c == 0x0009L)
8 t8 z$ m5 f$ v' K5. System.out.println("Equal");7 t/ ?0 l: ^, t
6. else System.out.println("Not Equal");
. f1 T3 I0 J. N( s5 @- }, J7. }4 E4 c3 P! L- J% P
8. }. k+ W* i% f6 M7 Q: e6 v' U
当编译和运行该类时,将会发生什么:0 c" c3 s, N) h3 U. t! H; V
A.        程序因为第4行将出现一个编译错误
% R4 W$ u& V5 V7 S* jB.        程序因为第4行将出现一个运行错误
- x" z7 }4 l. TC.        程序因为第3行将出现一个编译错
; I# `, T. I3 m( L' cD.        程序输出”Equal"
7 b2 ]7 e* g/ W* {. uE.        程序输出"Not Equal”* J8 z4 f  g+ y3 H/ t1 X) h5 p
3.        读程序:
" ^& M8 L' }! T( j. ?1 k" R  S1. public class StrEq{
# E% l" |- Q6 X) p2. private StrEq(){3 O' Q8 a7 G! g9 [8 s. ?/ A9 r8 A! @. M
3. String s = "Bob";; M7 y2 w7 e8 C5 R, {, u
4. String s2 = new String("Bob");0 E$ D) ~( g1 B" v
5. if(s == s2){# B, N  V) e) V; o% f2 ~
6. System.out.println("Equal");4 Q% p8 z" t9 `- N
7. }2 j: Y( y9 q9 @3 r- O% @
8. else{1 U! i. s* `2 a. ]! K: ^
9. System.out.println("Not equal");
% N' I9 _2 E$ Y10. }
! }* c3 M* Q7 u11. }3 p- Y0 U9 z! T8 Y
12. public static void main(String args[]){/ H1 n5 Y$ h  I) S, d1 D
13. StrEq s = new StrEq();, E& N& i' Z; T
14. }2 T4 ~: E/ D# x# e, C
15. }0 L* C0 v/ C7 Y$ Y& N8 V, Z# h4 I3 _
当编译和运行该类时,将会发生什么:
" d- `, O# I9 c! u; z  G5 tA.        程序能够编译,并且输出“Equal”
: M* L, i9 i8 VB.        程序能够编译,并且输出“Not equal”
5 H0 }$ \) _2 H- r$ d6 OC.        程序因为第2行导致一个运行时错误* Z+ O. @: V0 ]8 F8 k1 M, P
D.        程序因为第2行导致一个编译错误5 M% P! ^/ M# }; t$ Z; `' L
4.        以下那个赋值是非法的:
$ F: P) X! v8 ?% {# U& P& f, T3 m% lA.        long  test = 012;, }$ h1 B& R$ Z/ p5 A( b
B.        float  b = -412;
6 \* }1 i2 ?) |; i  N* F# NC.        int other = (int )true;& ]0 R5 _2 d  x9 K0 _* u2 n
D.        double d = 0x12345678;2 o6 a! ^3 S: ?: h+ U, k
E.        short   s = 10;
' D# U( u' A* S& b  [5.        读程序:1 v" k& t" [! A, {3 G
1. class CompareString{: X- H" B3 M- K: d
2. public static void main(String[] args) {- w  C6 J' ^0 t
3. Integer x = new Integer(5);
) \/ i( J& P6 I: d  {! f4. Integer y = new Integer(5);
8 x! \* E3 V5 r5. Integer z = x;
( q! H/ U- j. r9 D6. if ( ______ )0 ~+ d* Z2 [: e% i
7. System.out.println("true");  H& T$ {) y$ z
8. }
" D- [1 P' A3 x0 t/ f/ e" m& ~9. }
% G4 Z% |# t9 Z! J6 Q, n以下哪个选项填入第6行后,不能输出true:
  [- Q- M) y% w4 gA.        x==z
$ c7 i$ d* N8 Z: l1 `* `0 FB.        x==y. w4 D5 ~& q9 Y1 @5 a
C.        y.equals(z)' b3 E! m2 e# b; y% I
D.        x.equals(y)
0 \( w' |. v! y/ C+ ]6.        读程序(双选):
& z' B9 n! \( j0 ]2 b% B1. public class Declare {  `1 z' [' J) V
2.1 k5 J: \$ O9 z$ o2 N
3. public static void main(String [] args) {1 h: U5 `7 o) G& m  H( }! V
4.6 u2 J7 V  ?. w
5. System.out.println("The variable is " + x);( v, I; ~2 b0 ~* W; S3 @& o4 Q0 _
6. }
2 ]9 n5 B4 e1 h; h( ^4 |& V7. }, m6 I) V9 j8 _! Z
以下哪个选项中的代码可以使程序编译通过/ p' M( v% K, {8 x
A.        把“int x;”放在程序的第2行
9 ^" k" W- h3 _B.        把“int x;”放在程序的第4行
# ^. n% b+ r) d. l3 C9 z* PC.        把“int x=5;”放在程序的第2行  b9 F) S& x) Z! M' A6 E
D.        把“int x=5;”放在程序的第4行
+ ]7 K0 @' F5 W7 J0 lE.        把“static int x;”放在程序的第2行8 a9 k# V8 J+ y2 ?- }7 A* e

2 V* h6 |) Z7 M0 U2 E+ Y
" x- O2 T! g* b3 N+ o4 h: ~- q8 A+ n5 Y# H6 {0 ^5 m5 ^9 I3 E: [
7.        读程序(双选):" w& P" T) K/ m; g* v* E
1. public class Child extends Parent{5 @& |6 e  G7 H
2. int a, b, c;
- U  W' `4 a: t% J; Y3. public Child(int x, int y) {/ C  ~8 _( @+ R- N
4. a = x; b = y;
6 U# g$ c$ o+ o# y5. }
7 Q7 }! q8 k. x8 ~: E6. public Child(int x) {
# h! ^# F$ r: [1 a5 }. O: B7. super(x);
9 I( [5 A1 ^% R7 {+ _! c8. }
- Z1 c9 c, |& d6 P! B2 z9. }6 x5 S6 i( o& H5 h: Q
为了能使该类编译通过,下面那个构建器必须出现在父类中:
7 k3 K, C/ S- AA. public Parent(int m,int n)
( F, e  U( n5 ?* x: Y9 E3 I. YB.public Parent(int m)  p5 b* H: ?8 `( o: Y
C.public Parent()
5 R4 w% }2 q) Z# AD. public Parent(int m,int n, int o)2 O- x; I, s  f
8.        读程序:" W: q/ o4 l5 W0 a' A/ z6 \/ U5 Z
1. public class Derive extends Base{7 Z4 L$ y% y0 N
2. public static void main(String argv[]){, o0 U  m+ z5 h+ G8 |" p
3. Derive a = new Derive();& A% k6 i; ]# E" i, K( d: ]" n
4. a.method2();- i, ^# r3 n! K
5. }/ w5 C5 T+ c2 E1 y8 Z
6. public void method1(){0 A$ I4 Q, n- |  R7 F. w0 Z
7. System.out.println("method 1");
8 m5 H" U+ {8 T8 i- J+ M8. } , ~* s' r0 X: l' \
9. public void method2(){
  i( k2 e, S0 W10. method1();
, o5 U9 W6 J- m- z" c4 R1 {0 R11. }! U" z* z: a6 _8 B1 {
12. }, }7 q# u% K3 J% D
13. abstract class Base{# E/ p% V" W9 V* D8 v' t% p4 y8 B: m
14. abstract public void method1();
+ F9 t+ e1 j  H# w* Q15. public void method3(){
8 f) N1 i8 ^3 J7 v16. System.out.println("method 3");
, \4 t" J) I+ ?# J, k8 c17. }
8 ]3 E- n- O" a& Q+ V}
" G. p2 q7 }1 ~. S* G当编译和运行该类时,将出现什么:" I5 ~2 i: B+ Q  \
A.        程序输出“method 1”
, p2 b. n: I0 N! x% N- h* PB.        程序输出“method 3”
# D6 @9 c; g) r1 aC.        程序因为第15行而出现编译错误; j- E+ L2 _7 q( o
D.        程序因为第15行而出现运行错误
( D2 j: F$ y) r9.        以下哪个接口的定义是合法的:* Y2 K" C. D" v5 b9 U8 c9 w6 `
A.        public interface A {int a();}
# c8 q" G/ o/ t& H, @B.        public interface B implements A {}
3 R7 w3 b8 s; m9 U# i. N' t1 ]C.        interface C {int a;}, W  g0 Z$ W4 c/ m
D.        private interface D {}4 ~4 C& G8 i$ D- u: K& I
10.        读程序:5 J' L- [3 O% f; h' x. p
1. //File SuperClass.java2 K' F; W: S7 [, C2 Q
2. package MyPackage;
2 R  j9 V2 m1 `+ f3 R1 k3. class SuperClass{
' p! k" u! j9 H5 h' \6 j, @4. void myMethod(){
  B$ u: F/ E# g# W# }7 ?5 J1 Z5. System.out.println("SuperClass");
% I% F5 P' w+ l0 @6. }/ c3 F" I: r! X1 ^$ x! q
7. }* M" u# q+ ?& h) @. V
8. //File SubClass.java
0 Z0 X" {/ `% \# ?* Z$ L3 q9 V# J9. public class SubClass extends SuperClass{! z6 m6 s$ F; C- D$ B3 E6 E
10. public static void main(String[] args) {, y4 F9 g6 P; d
11. myMethod();
& T: q5 v) K/ f3 @+ F; x; W12. }+ g; e; w, p, J* J6 O# \( q
13. }8 m: |' a4 `1 \$ w' d5 Q, X, b
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
) h! z  O# m9 p7 B" x  zA.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
8 M1 H+ N3 t  A4 C# f7 ]B.        两个类都回出现编译时错误
" \2 l3 i3 r2 N" u3 HC.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误
! I( d$ }/ v, Q: dD.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误
) v  e+ P  }0 b# K) ]# M) j, t4 K11.        读程序:" V4 ]/ E- S) j9 P- q- H" S
1. public class Test{
8 A8 l5 g% `; Q( Z2 r% S2. public static void main(String args[]){5 v# h% ]& Q" [* T6 J# P
3. int[] i = new int[5];/ j. K# ~2 x2 R1 c
4. System.out.println(i[5]);: n% ~9 U- c' m$ [+ H8 G
5. }
( P' \* a4 y* X6 c# p- r6. }
4 ~- a* [. I8 N+ J) R4 ~1 c0 A当编译和运行该类时,会:0 B4 g! y9 u1 C5 x
A.        出现编译时错误/ f. R$ j. v3 ]# `# ?& C
B.        出现运行时错误
8 B7 [6 I) d5 d, W( i* f  F$ t4 AC.        输出0
3 A% t: S) _- u( e6 K( FD.        输出null
$ g1 G1 f# L" K5 v12.        以下哪个选项是正确的数组声明或初始化:
5 X) W# r3 D2 o2 x7 y, {5 b4 J6 S! L& AA.        Array sizes = new Array(4);/ w/ a# @" M5 ]$ M9 m
B.        double [] sizes = {1, 2, 3, 4};
9 R( c, n$ f0 Y* _3 V+ f, VC.        int [4] sizes;
4 h( X" F1 d4 t7 P- Z; _1 oD.        long sizes [] = new [4] long;8 L5 K! s, [5 W0 F$ @' n
13.        读程序:7 }9 H% M' q0 a  X+ |0 S
1. public class Initialize{0 B8 D0 \. `" S- Z5 a7 p! X
2. int x = 200;
9 O/ i* k1 w- x5 T5 L3. static {
: T, {" G8 u) D6 h  A6 M2 O4. int x = 100;4 B7 c' ]1 f8 n3 E# w1 Y
5. }# r" I  Y3 U. c( \/ d! s* J
6. public static void main(String[] args){! m1 p" ]6 I6 g7 C2 y" h
7. Initialize init = new Initialize();% {, {8 Z6 y6 e" B/ |
8. System.out.println(init.x);2 z, f7 p$ P  V* p8 s# w
9. }" I/ l# T+ E+ |/ A3 H5 Y
10. }" J& i. q6 I8 X
当编译和运行该类时:
# U) [* W% ?/ w! p1 O- U$ `1 XA.        程序因为第3行产生一个编译错误0 D, ~5 ?' j8 Y* J; a
B.        程序因为第4行产生一个运行时错误& m7 r: [, ^1 ]$ P+ A
C.        程序输出100; U/ i( E6 A- b8 J& X, s
D.        程序输出200
# M3 k, c( T3 k! S, ~14.        读程序:
- W( \. \  E' v! R9 {1. public int abcd( char x) {" a) b" X( M. q8 S
2. if ( x <= 'M' ) {4 L" V  b& f/ n0 |
3. if ( x == 'D') 3 b. u0 c+ x- K" ?3 `
4. return 2;
3 P$ X9 d. r' j  k, D3 i7 u5. return 1;# c1 q+ F+ ?" _$ n
6. }
& P0 i8 p, h( g' o0 i7. else if( x == 'S') return 3;1 ~. C  l# F1 `
8. else if( x == 'U') return 4;2 N% E7 b6 H/ {6 R. l" \+ t" N! ~
9. return 0;
. t/ m* C0 O+ |2 {# D10. }% V# c4 b/ u9 _3 _/ w3 Q
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1# O: S. |* U; j, @3 s2 B# k
A.‘X’4 S0 J' ^! u, k
B. ‘A’
% q  P: U! J7 Y" _. ]% OC.‘D’& u9 ^- _) t9 Q, S9 `* S; x% g
D.‘Z’* Y0 v+ c% |7 @
15.        读程序:& I# g+ s4 ?' w% u5 V1 ~
1. class TryTest {! s+ g, l( P8 |5 ^1 O' Y3 x8 r
2. public static void main(String[] args) {
2 S4 S/ H8 @$ k; n0 n7 T. r3. try{
. a' N! m( _8 v4. System.exit(0);
5 J8 U  _* {* [/ [0 `7 X5. }$ ^) Q* A7 f1 D
6. finally {3 ]5 }0 Y# ^1 G' J- a
7. System.out.println("Finally");: v) \7 h. I  Z! A% o
8. }1 b" g+ z0 O% e/ _& d% L# q- N
9. }
+ L  w6 c" i. W+ k. s$ ^! T10. }
; T+ i7 H1 Y# n4 w& ]当编译和运行该类时,将:
) {9 g: U5 s. k( wA.程序因为第4行出现编译错误& _( E: p  l/ v: q' \6 \
B.程序因为第4行出现运行时错误
) i* g" m5 x& c  _C.程序因为第6行出现编译错误- `( A& q( _  I+ ~
D.程序因为第6行出现运行时错误9 h# U- v& X# I' |  ~
E.程序输出“Finally”- R1 c2 p& @3 Y0 |5 ^8 n9 N+ H
F.程序可以运行,但什么也不打印
' m0 _, V- q% `$ f7 ~
- |; `3 Y& }! J  x& [* S16.        Given the following variable declarations:8 }# B; \  r% g( c$ p
Boolean b1 = new Boolean(true);% H; R4 [, d) e5 C
Boolean b2 = new Boolean(true);
6 U& o* P" O' D+ w0 G* o4 `Which expression is a legal Java expression that returns true?
' P, p$ @6 l* [6 ]A.        b1==b2; T# B* \& h* V1 [
B.        b1.equals(b2)
) m/ N5 e7 _' JC.        b1&&b2% ~" ~/ f8 b' d3 \5 s. R* u8 d  e* H
D.        b1||b2
+ a% Y" r: d  M1 ~& nE.        b1&b2
) J; }5 P/ }; B3 b9 U* x, ZF.        b1|b2
0 h3 B% M/ Y3 j/ D1 V17.        Given:
8 u5 T" ^0 }1 q1. public class Employee {, o% f6 }9 l) b# C
2. / T7 X$ x% X6 p- Z6 `
3. }3 O7 P) Z% s8 p, V
4.
' N$ R: ~' P" n, K4 m# M/ I5. class Manager  extends Employee{
# f% W" ^5 g3 z8 v. K) @$ G5 c6. }
% F0 P# k! \7 H. c! YWhat is the relationship between Employee and the Manager?
: v5 Q9 R) m2 e0 M  u# t/ RA.        has a  J' |- p9 J+ x! X  x: N) i
B.        is a3 k0 p" ^0 j, V3 `
C.        both has a and is a. w' H( X8 t) z4 i
D.        neither has a nor is a, ?+ u! K3 e8 ]8 D* P" K
18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?/ Q+ ~4 E: g3 ]3 }2 d+ o8 U
A.        BorderLayout$ V# B/ \7 y0 k4 q
B.        FlowLayout
5 M0 J6 n# v, H; O5 sC.        CardLayout
' a3 u" ^: A5 [6 w0 tD.        GridLayout
- v+ _$ u5 m* y7 [9 A( I9 w19.        Which of the following AWT components can generate an ActionEvent?
% k+ s+ c2 g# p9 D% u: a# p+ o4 CA.        java.awt.Button
% u* H" _2 J6 k: LB.        java.awt.Panel
0 g1 z2 _7 {) [; u* {, t) a- [C.        java.awt.Canvas
3 k) n6 M# Y! y( Y$ KD.        java.awt.Scrollbar
0 r% `) I5 [" t. a5 I0 x7 L( ]" h20.        What kind of Stream is the System.out object?$ \# ?, V& R; k/ y0 v
A.        java.io.PrintStream
( p7 Q$ _5 B. v) i/ yB.        java.io.TerminalStream
+ O, d* V" h; D# V1 iC.        java.io.FileWriter) W) Q: B! H5 ]$ a6 h' W% E
D.        java.io.FileWriter' S- h0 n% m4 }' @* H! X3 d
21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)  d7 S& \7 r7 Y. i9 M" G
A.        java.awt.event.FocusEvent5 l3 ]- i. R" u+ g# F% A) ~/ Z/ ?- R
B.        java.awt.event.KeyEvent
* K) g6 t( H. ^0 D# w9 TC.        java.awt.event.ItemEvent
3 e7 f+ i* {' Y+ ]% R! FD.        java.awt.event.ActionEvent
/ m( w" {- t. V& f6 L& J22.        Which of the following methods are static methods of the Thread class?(双选)
5 ?2 S1 i7 X* B- j* qA.        sleep(ling time)% p  ^0 {! @4 @2 p3 E- k& i. u
B.        yield()
* F. d5 n, D" C8 _0 e1 ?  ^C.        wait()
/ u7 j* y( k! c5 z" t/ lD.        notify(), J$ L! h1 o# f( h! L  a& K! G
23.        Which method do you have to define if you implement the Runnable interface?
8 {4 U) z) M# E6 B3 m* }* YA.        run()' i$ y, V% W# {
B.        runnable()
( U" ]- G/ W8 c4 a: g- E0 j0 TC.        start()
: |" a" {2 O; t' t6 A8 _- f9 ID.        init()
) R3 ^. B: l& v; [- A5 YE.        main(): A; p% c, }& b) E1 W! N
24.        Given:
5 }; r5 m6 m) R# p! K; X1. class MyThread extends Thread {* T+ |0 ]& I* \) N  [2 o
2. * h4 C" \1 R/ A* o7 w7 ?! ?
3. public static void main(String [] args) {# b2 u1 L( g! L1 `% I
4. MyThread t = new MyThread();& B1 o6 Y" M/ p5 T. b. J
5. t.run();' |7 E$ d& @2 \. v
6. }1 ~& Q! X( }& I# V) K
7.
  [2 l3 Y8 q7 Q2 p8. public void run() {5 S. V  F: ~/ ^% s4 T* G
9. for(int i=1 ; i<3 ; ++i) {; f7 n1 b1 ~  C
10. System.out.print(i + "..");6 d6 G& }9 W6 I$ m, B& m
11. }
& u# q; c$ k' \6 T6 J5 Y# p2 p- l$ v, C% N12. }
6 {3 K% ~) h- S8 I3 h13. }
0 J4 [2 {$ |) e. @What is the result of this code?C
; i2 [5 O! K+ k( J2 [3 SA.        This code will not compile due to line 4
" i" k% ^, k1 ^. c/ T! XB.        This code will not compile due to line 5
" \7 A: y! j  k& s$ u4 B( \& u9 NC.        1..2..2 e, g+ H0 l2 L) h
D.        1..2..3..
+ ~6 U, M: ], t) r7 n+ K25.        Given a local inner class defined inside a method code block, which of the following statements is correct?
6 |* ]5 A: N! V5 QA.        Any variables declared locally within the method can be accessed by the inner class* n: U, A" E( H
B.        Only static variables in the enclosing class can be accessed by the inner class, X+ C/ K4 f5 k& ~  K3 ]
C.        Only local variables declared final can be accessed by the inner class
  U+ F! n7 P6 p, E1 FD.        Only static variables declared locally can be accessed by the inner class.# ]) {0 r  F$ O! X# c
! q/ i% O; M' m* U8 ~2 l
* H7 `5 l1 B  ^6 z
. S! X8 K& A. L7 z2 b
26.public class SychTest{
+ o9 H9 w+ F. K+ F1 T   private int x; . B+ z+ e, d! n" j) G4 R8 o' w$ G
   private int y; ; a8 \( G1 l3 H6 j/ F/ D+ S. B
   public void setX(int i){ x=i;}
$ `7 l" t  f& G% H! \   public void setY(int i){y=i;} 6 b% g1 I+ v8 p! P3 ]% q* {
   public Synchronized void setXY(int i){
; t) y9 ^" ~+ f* i0 _! a2 M     setX(i); : t# T% k4 D. U
     setY(i); : z1 X! v. ~2 \; m
   }
6 d% k: j( @' K( g, j   public Synchronized boolean check(){
$ ?0 K1 Z; j9 h! }+ _        return x!=y;   1 U8 ?7 h6 O% o% z- ~  x5 A$ k& a
   }
( R6 b5 `: U4 l& G, |9 J   }
/ X' L& R4 E: u% A  e    Under which conditions will  check() return true when called from a different class?
; y, |! R* @+ l) \   A.check() can never return true.
6 v4 r  l1 _* B" {   B.check() can return true when setXY is callled by multiple threads. , y* F, S; @7 {4 f2 s( b) p
   C.check() can return true when multiple threads call setX and setY separately. + l6 @4 @  t: W4 A) K
   D.check() can only return true if SychTest is changed allow x and y to be set separately.
/ w  J7 w5 |+ g+ u' D& |, S  [) s3 D6 N6 L5 y
27. 1)public class X implements Runnable{ 2 r  ^& L- F7 a
  2)private int x; ! o( l3 W0 [6 k7 d# ]# n/ i
  3)private int y;
, S* `( h' j8 p0 w" `  4)public static void main(String[] args){ 9 p* `0 Z  X7 j3 M- ~& w
  5)   X that =new X();
, m5 ]5 [( X4 ^0 c* a4 T8 ?  6) (new Thread(that)).start();
+ ~  s6 M" E6 r4 ?  7) (new Thread(that)).start(); % r$ ?3 j2 z- {+ R. @. H
   } ( C$ C' Z. S/ z0 K3 Q
  9) public synchronized void run(){
' c  o9 Z  z) m4 P1 J  10)  for(;;){
; T2 `6 j$ @  `" H- J7 t  11)      x++;
' K0 a- `' l- M" Z6 |& C  12)      Y++; & A4 o8 Y1 d; A* B
  13) System.out.println("x="+x+",y="+y); / K5 V8 M5 @' z) C6 y! u! X3 u
  14)    } ' O7 g- c+ h7 D
  15)   } - {3 h0 i$ |: I0 s; Y2 C
  16)  }   2 z0 @9 T, S% ^& P0 X/ n! X2 U
    what is the result? ; P) g0 r: F3 ~+ v  z. W. F
  A.compile error at line 6 : e6 u. |5 Q/ [# m" M5 \3 v
  B.the program prints pairs of values for x and y that are
( \  z. e0 U0 ^& D; P5 T& J8 l" f! n    always the same on the same time 4 s3 `/ V3 s4 D  }' E6 ^9 Q

4 R- T! J: H& g8 F1 {28.class A implements Runnable{
0 ~+ t2 j/ Q5 M1 U  int i; ( R* \9 s6 s+ Z
  public void run(){
# l7 T. P3 }$ P1 H, h; P# t   try{
  Z. T0 i# s9 k* ^' c       Thread.sleep(5000);
) @' ~3 ?$ y8 [& \( E        i=10;
2 O! ^+ Q/ g; c0 N% f# U       }catch(InterruptException e){}
$ y! a5 s- O. p8 c       }
: k- B. k4 k5 T* U! P       } - u# M3 q, f, m" F9 U
   public static void main(String[] args){
3 I2 S. [# S3 T      try{
' m  p: d1 Y* \, ]" Z) q  j' ]' F         A a=new A();
' u- z9 N( V% A5 |. e         Thread t=new Thread(a); 2 b0 _2 @; J" b
         t.start(); ( U  I6 c( w3 s/ M/ w% j! Z# ~  `' \
  17)
5 K# _1 M. I* c! b0 H% V      int j=a.i;
5 M+ N, e0 u& S% N7 j) C* Y  19)
" L9 x) N% Y4 f$ s# @      }catch(Exception e){}
; o' P$ P, s- A+ N$ ?: o: p      } ! d4 f4 h( p9 g7 s# q
      } 9 ~0 ]# E, q  K! B: w- {  r5 R$ }
  what be added at line line 17, ensure j=10 at line 19? 5 l- I; h. c1 p$ r. ]+ S2 \
  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   
  P% s! F# k4 Q; [  E.t.notify();  F.  a.notify(); G.t.interrupt(); 7 }& z, h) E: L
29.1)public class X{
- t& Z, s& G: X* v( k, E) T9 H, D( N0 [7 L  2)    public static void main(String[] args){ ) U. p1 t4 |! j9 S4 H; }
  3)     String foo="ABCDE";
; {' k* Y+ F& k  Z: e* }, N+ B  4)     foo.substring(3);
# f2 _2 }4 A+ v, R  5)     foo.concat("XYZ");
9 p4 z  g0 M' d, k8 I7 I: _  6)    } 5 k+ ~. @  a8 J! H6 d& z: B
  7)   }
' C3 j% o* N6 a% J  what is the value of foo at line 6? # K8 H- i, B, [0 v0 I) D
30.  public class Test{ ) x& o' ]- \: I6 A" |9 m  Q6 O% o
   public static void main(String[] args){ 1 v1 \" o2 l; m) h
   StringBuffer a=new StringBuffer("A");
+ \6 T* ?! i" u+ _' z: y3 J   StringBuffer b=new StringBuffer("B"); " f5 v( w# s) s2 P- h" P; s3 D
   operate(a,b);
! R$ V  s" U  U3 y5 {6 w+ Z   System.out.pintln(a+","+b); 2 K8 H" r5 O, L4 ^1 \+ `
    } + `- l  \/ P# H$ ]7 [8 \, y" P
   public static void operate(StringBuffer x, StringBuffer y){ 7 c  v0 u! d8 J  l7 f& @
    x.append(y); ! n# i+ H; w7 t+ g1 f$ [
    y=x; : s; l/ }( z1 G# o8 B" d
   }
# J7 H. A" f; W; w   }
6 d5 d$ V! D1 ?! t% j   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享
# p+ G' }& g2 b5 @, I我已下载。。。。。
4 B- [% c' G9 M- D# A) x' t5 T6 h特感谢您的大公无私
weichl 该用户已被删除
发表于 2005-9-29 21:51:28 | 显示全部楼层
感谢楼主分享
发表于 2006-6-24 19:00:04 | 显示全部楼层
JAVA还没学呢,先下载来再说。。。
发表于 2008-5-23 21:00:52 | 显示全部楼层
支持楼主。
发表于 2008-12-15 08:22:28 | 显示全部楼层
谢谢楼主发这么好的东东!!
发表于 2009-7-7 16:26:16 | 显示全部楼层
您需要登录后才可以回帖 登录 | 建立账号

本版积分规则

 
QQ在线咨询

QQ|小黑屋|手机版|Archiver|美河学习在线 ( 浙网备33020302000026号 )

GMT+8, 2026-7-9 14:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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