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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题
" ~* ?( R; K( r0 Y* E( m; |1.        给出以下程序:2 ~% m/ r/ R% C' e) H6 X; ^* [
1. public class Colors {' R) g: M4 K$ o1 a% ]
2. public static void main(String args[]) {9 N; ]& K( U* L8 i7 ^( X
3. int n = 1;
. w) ^  U  ^- f. s. v4. System.out.println("The Color is " + args[n]);
, o: D/ b5 I1 B% D  n( f% F# e5. }: M; Q# `+ y: j+ c( z4 y) i, b
6. }
/ X3 f; ]$ J7 `* }, q假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
4 @1 \- p# E2 D. mA.        Colors red green blue yellow
8 z0 @3 ^" v0 N5 f! ]$ ?* KB.        java Colors blue green red yellow1 V1 b& n8 h) p& h2 H
C.        java Colors green blue red yellow
1 F  f: i& ~! H! @! GD.        java Colors.class blue green red yellow
' S0 P% k$ v* C+ V6 r3 GE.        java Colors.class green blue red yellow
1 b2 |7 v, i# r2 u- p/ b2.        读程序:% \& E+ I- P4 H1 T" W  P5 R: j
1. public class Test{7 O3 T5 T1 u4 [2 E
2. public static void main(String args[]){
: U2 k% o4 @8 u% k# f3. char c = '\u0009';& F  m0 Z- u% w6 n: u
4. if( c == 0x0009L)- b/ D- g( v1 S# F2 d3 X
5. System.out.println("Equal");
9 P$ b1 W0 ], d: I) k6. else System.out.println("Not Equal");
0 G/ F) C: Z1 T" q7. }" ^( n% S+ y5 M. n0 i2 K
8. }
. r8 e, q+ K5 \! a当编译和运行该类时,将会发生什么:4 r' _; k! I! G/ x
A.        程序因为第4行将出现一个编译错误
( P7 s6 `7 U; U1 B* HB.        程序因为第4行将出现一个运行错误
7 _0 o8 n% d! RC.        程序因为第3行将出现一个编译错
9 n) V/ I$ w3 G  f4 g5 R0 mD.        程序输出”Equal"- Y/ K; K5 {7 H" V
E.        程序输出"Not Equal”5 F# V, y7 y+ `, T: f
3.        读程序:
! C  D* Q8 U# L0 X. m1 S) _7 d$ a  A1. public class StrEq{: f/ Q4 m9 W/ [; z% Z' v. Y" z
2. private StrEq(){% S( F) [2 F& j* I  @5 `
3. String s = "Bob";
) u1 t+ V: z! u5 Y4 ^4 C" D' g4. String s2 = new String("Bob");, Q. M! N# M& F& i5 G7 ~
5. if(s == s2){2 G& a2 _7 U; k
6. System.out.println("Equal");3 y. t( H) i" B0 e- x4 i  k
7. }
6 R% ]2 {, K/ b0 }6 [. N8. else{
! {, E2 Q3 E4 N$ t9. System.out.println("Not equal");
) {7 g) Z& }1 N1 F  C9 W+ }- m5 M10. }" b' y( X& l  S% v0 K9 Q& Q' l
11. }( \3 m0 o" a: f
12. public static void main(String args[]){
- N$ P* \( P2 R* a( w2 ?13. StrEq s = new StrEq();0 {2 k6 _+ M# y: o
14. }
- i1 N$ R5 S) P15. }
' v. W6 i9 B9 Z' w" H: y/ U5 [0 a当编译和运行该类时,将会发生什么:
! S$ M( f( w; P" vA.        程序能够编译,并且输出“Equal”
. d- c9 h* W) [- N3 QB.        程序能够编译,并且输出“Not equal”
& a6 l& I! }  ]' A& W+ |C.        程序因为第2行导致一个运行时错误
% n8 a2 x$ \0 `8 s. ?9 x+ @- d/ L  SD.        程序因为第2行导致一个编译错误
/ `! s% q: M  g4 A5 K4.        以下那个赋值是非法的:
# X! ^4 L& Z8 r8 ZA.        long  test = 012;( T# k# p% ]6 Z
B.        float  b = -412;
1 v5 ]) x' b& a5 ?" v. Q+ nC.        int other = (int )true;
, ^! |2 E/ K* Q( F3 p6 ZD.        double d = 0x12345678;
' d. u& p8 @; C% G) o4 x1 F2 LE.        short   s = 10;: `; j  D0 v0 Y) W
5.        读程序:
, Y/ z3 b% d. b4 A1. class CompareString{
- u7 Z3 d# N5 [+ m  Q3 G2. public static void main(String[] args) {
2 ^; r! ^( y/ K7 c8 o; N  ~7 {3. Integer x = new Integer(5);3 a9 W/ x) t# ?3 [" H, V
4. Integer y = new Integer(5);
: `2 l* p! |9 B9 r9 K+ T% W! z5. Integer z = x;( y2 l; k1 V, V  k7 P; J
6. if ( ______ )1 v, c* v) C; O9 t( }# V4 A
7. System.out.println("true");
$ D" N& @7 \/ w* r) _8. }# f$ Q) a  h/ M9 }* @: m: g$ L
9. }
3 F  L5 f* M) t! y3 G0 ^2 v  I) a以下哪个选项填入第6行后,不能输出true:
+ [) w9 c9 Q- HA.        x==z$ N; Y, O) s! j* m! [+ a/ }
B.        x==y
+ ?* Q1 n; d" e. n+ X2 D" [2 M) EC.        y.equals(z)! _3 C( E6 W0 k! g5 f3 y: a7 U
D.        x.equals(y)/ W& c3 @2 Z: G. D$ H/ `: n; ~6 o2 @
6.        读程序(双选):% R: i1 s8 g& c; _  R& N
1. public class Declare {! s9 T1 |' b9 H
2.
- D2 }) \$ f- `$ l: l9 C3. public static void main(String [] args) {. W# N& B0 R2 p$ J" v9 n
4.& Z- b" F4 L0 L9 Y( D* u' ?
5. System.out.println("The variable is " + x);
6 {  w3 \! s+ r7 z" @6. }
. _- C8 ~, o, O% a  Z6 R, r7. }" z& Q0 d2 Z! F: P7 R
以下哪个选项中的代码可以使程序编译通过
& k4 r$ ~) j2 l8 {* A" wA.        把“int x;”放在程序的第2行# c9 d2 @/ R! l( J5 E% w
B.        把“int x;”放在程序的第4行
. z9 K4 m" j* z5 a. m* MC.        把“int x=5;”放在程序的第2行, c% U) L0 y" [/ R
D.        把“int x=5;”放在程序的第4行
; V2 ]( R) C1 c" Z6 o6 BE.        把“static int x;”放在程序的第2行, P, s; V9 O* X& ^
2 T. c* T( g3 ?) M7 K8 ~- l$ a, b

# A% u; f+ N/ `! z2 u( l% w+ Q/ j3 y0 f' ]! M+ F+ H- L
7.        读程序(双选):# p+ n# S, X- A( K
1. public class Child extends Parent{
# i8 [9 P* h# `. j- H2. int a, b, c;) ^% u7 G. C3 E8 G% R
3. public Child(int x, int y) {
9 [: x6 ^' U. M4 k3 r; u5 }5 Q4. a = x; b = y;4 T3 c2 h9 z0 T; y& A3 A
5. }
+ z5 E6 z; D+ N5 }% c6. public Child(int x) {% j; A0 s8 m9 Z" K$ H+ K! o
7. super(x);
1 n: d# C6 o8 E8 N  \, F8. }
7 p0 }5 z4 F0 f9 q9. }
; d! U) _  K/ O; i2 {* e; z+ w2 N为了能使该类编译通过,下面那个构建器必须出现在父类中:: i& ^# h( Z% T( \( x1 w4 m
A. public Parent(int m,int n)
4 K( ]/ R- z) J1 T1 W8 p* hB.public Parent(int m)
# S) B. d. s2 G# ^& rC.public Parent()
# m: P, K& g: y2 ID. public Parent(int m,int n, int o)$ E2 T: r9 G& h! }6 y; }/ \
8.        读程序:
- @/ B# ^( f  V  f, T7 J! |1. public class Derive extends Base{- E* h2 q; t( p' S  K
2. public static void main(String argv[]){
# f. p/ }8 F, ?/ U/ ?3. Derive a = new Derive();
. v( u. |$ t! d6 C4. a.method2();6 \  Y- e2 z8 ]+ m7 u- i
5. }7 y6 t4 C) M* P; J& H
6. public void method1(){# u7 x+ z3 A6 o) J7 o
7. System.out.println("method 1");
2 B  G; x$ }6 @$ C8 H8. }
. T; R9 q9 |+ N1 }4 I9. public void method2(){
" f/ E3 c+ j; B  Y. Z% N, a10. method1();
, a& j: L4 N: ]0 w11. }
: o* c! A7 m5 ~8 v& X12. }6 }9 q9 f2 `0 d+ j4 H
13. abstract class Base{
8 S8 t3 @% v" G. O% [0 D14. abstract public void method1();9 M$ q2 y, Z% O* G) |# A! a' M
15. public void method3(){8 s  ]/ @. ]3 G
16. System.out.println("method 3");
1 q' z$ @$ x2 o# z- G* ^17. }7 b% X( d# w+ y; w' J/ g1 y
}
1 @4 k, @/ p+ `# F当编译和运行该类时,将出现什么:
* r" x, b3 h- P- WA.        程序输出“method 1”, _1 {5 P8 ?" A
B.        程序输出“method 3”
! K9 n% i  ]) h* O4 HC.        程序因为第15行而出现编译错误
: X% k- B& `, v" X7 C5 _3 _D.        程序因为第15行而出现运行错误
' t2 n- Y+ ~* h6 ?/ F9.        以下哪个接口的定义是合法的:
, V3 i! X2 m" [9 Q3 q' F3 tA.        public interface A {int a();}4 Y" {# G* ~# i: ^" P  G
B.        public interface B implements A {}
- S( n( e4 K$ E  I& f! TC.        interface C {int a;}6 F) f, t9 g% o
D.        private interface D {}
0 P; k' D$ p4 v* V. ]10.        读程序:
) ]7 G& N! a% G, p1. //File SuperClass.java8 Q6 k* S$ V4 u3 v& ~
2. package MyPackage;
' J0 B* N/ F( a! {) t3. class SuperClass{& @( A$ r+ v4 i( G% I: p
4. void myMethod(){0 h; u( k. @- r! ]5 {
5. System.out.println("SuperClass");+ s; x; _+ z+ C! s
6. }* a# S! S, h9 Z# l- G
7. }
+ V! k( H2 Q# h1 N0 ~  i1 u8. //File SubClass.java, U: _4 x3 N* {$ [
9. public class SubClass extends SuperClass{+ b* b: k7 K0 a8 L( K# l
10. public static void main(String[] args) {" ]; L& W& W$ P$ r0 s
11. myMethod();8 d: u: f: m" t5 D- }+ G
12. }. v6 F3 m% X5 I
13. }4 n$ ~) D: V0 s
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
' u  b' N  p* tA.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”8 v: w  H2 r( k3 A# g% Z, c
B.        两个类都回出现编译时错误; C0 q0 J9 a1 |3 Y1 f
C.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误
- f& b5 s; C0 S$ D5 L/ C, mD.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误
5 [# w; f  u; S) ^% I; o11.        读程序:( G7 @! N/ _/ k; \9 v" S9 q
1. public class Test{) E, c5 d  O& \) a% X7 k
2. public static void main(String args[]){
/ B2 ?! p; @! u' U' h0 F$ p* S8 m. W3. int[] i = new int[5];. t0 \+ `9 n1 X: [5 Z8 U5 z
4. System.out.println(i[5]);' j$ o: m: q- u7 d& ?
5. }; R  V- v: {, v7 q2 d
6. }% |) d( Z: `7 g; Q( s
当编译和运行该类时,会:+ d7 x7 R' r# R% B( e3 v9 J& Z; D
A.        出现编译时错误
; K" n& t: y" L5 o* k# b  K! XB.        出现运行时错误
: w3 _- o- z: U7 ]3 @7 T$ T9 QC.        输出0
; }" k. v" s/ UD.        输出null. O% m4 V; G+ b6 b( v
12.        以下哪个选项是正确的数组声明或初始化:
3 Z. R# Z8 C2 f* _/ R- q9 wA.        Array sizes = new Array(4);9 k" v/ a) t" d2 D1 o$ k
B.        double [] sizes = {1, 2, 3, 4};6 o6 ^" m& v& E  G. V/ o" `, y
C.        int [4] sizes;
: L& l3 f  V0 u( MD.        long sizes [] = new [4] long;
6 _1 a3 o; s9 g! J% K" O' w2 j6 j2 S! k% s13.        读程序:
" S- b: U; ?: _7 }& n) \' @, @1. public class Initialize{7 G  S' E8 n  \6 g
2. int x = 200;  y/ ^5 r! o: p
3. static {
) l0 Q) g' |9 w% [; N4. int x = 100;
0 f( J$ S8 J7 R5. }* }  }$ ?5 W; E2 S$ `" ?
6. public static void main(String[] args){& ?/ l. ]! o. y4 M3 H: z. e- `  p" `
7. Initialize init = new Initialize();  A# f: `* `7 `! ]5 V" w& P
8. System.out.println(init.x);0 \) r. r; \- E3 ^/ Y
9. }
/ l% q/ F& _. q5 D10. }. c# m# S' u& B5 Y1 B
当编译和运行该类时:
# b( {8 d- g' D: a/ N/ W4 jA.        程序因为第3行产生一个编译错误
! W6 o7 w5 u2 s+ ]( T& y  {# z, eB.        程序因为第4行产生一个运行时错误
; G& Z( }; o! @8 XC.        程序输出100
$ l$ i6 ?4 w. s/ J4 k; Z% ?D.        程序输出200% p, k0 a% ?4 i" ^) V/ }$ d
14.        读程序:
2 ]9 U% ^* u' |. d1. public int abcd( char x) {" e7 ]- F; }# B. B
2. if ( x <= 'M' ) {
1 x* T+ N2 ~6 f" z: L3. if ( x == 'D') 7 d/ _: P3 k9 R5 }. \
4. return 2;
4 y) Z+ E5 l8 i! @' U. Z, o& ]5. return 1;. B( Y( \. ~( C4 c6 Y- B
6. }
1 k+ T/ [: o: ?2 E! Q7. else if( x == 'S') return 3;
# O+ D5 p5 C* m! G* Q8 v' _8. else if( x == 'U') return 4;
! d) ]" |: _) d! P9 C9. return 0;2 d# N1 @1 }% k
10. }
# W3 K) k; ^5 [* M在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
& L: {, @' O, @& Z2 yA.‘X’
2 y! R0 b$ `4 {4 {* M7 kB. ‘A’' K/ k" p  O3 A/ F2 e
C.‘D’
! @5 Q& A* X8 P* ^0 e; WD.‘Z’! V: T6 T# b% @2 J# Z
15.        读程序:
$ n9 @# l  w( K6 }1. class TryTest {, `# h% z( \2 B& T( E
2. public static void main(String[] args) {& y6 |+ K* s# l9 P' j0 w3 n# a# z
3. try{
1 H% A6 U! v& \4. System.exit(0);' P2 N+ H8 V" c- e* u
5. }5 N. c; @; T, V0 H, |" T' D: ]
6. finally {. I) I; C1 D! p4 P; m$ A3 n
7. System.out.println("Finally");
- `8 M- e6 J, a( \6 T$ C8. }$ `4 ^- r6 ~1 g! s% d
9. }- C; C7 }9 ^: T
10. }
2 W) v# Q2 \5 o1 _: K* U3 F1 j) b当编译和运行该类时,将:7 W  g7 _) c8 q9 ~' ]- q2 @+ V
A.程序因为第4行出现编译错误% p- I+ `; K) {5 H* Y
B.程序因为第4行出现运行时错误: @9 f2 {6 I& X  B' w5 Q
C.程序因为第6行出现编译错误
9 X8 q1 ?5 G' l  K  ^0 ]" OD.程序因为第6行出现运行时错误3 L9 I! s, c) P; P% v
E.程序输出“Finally”* r) t$ i" W7 h$ E( r. R, g, B* s% q5 a9 b
F.程序可以运行,但什么也不打印
" S! V% c$ Z/ Q- H9 n" L& q0 y
6 m  @- N+ ~5 q. h3 q9 U0 M16.        Given the following variable declarations:! g3 x/ t& w4 a% k( T! ]* m
Boolean b1 = new Boolean(true);
5 _3 M, K" D; C3 L, eBoolean b2 = new Boolean(true);
& x. d0 P% m) e6 B9 yWhich expression is a legal Java expression that returns true? $ }/ ^7 ^8 Q; l
A.        b1==b27 B3 ~! l. Q# P. g6 v0 M6 E: @6 i
B.        b1.equals(b2)2 r' @6 w" Z( l; [. i. Y3 [: Z
C.        b1&&b2
5 U. W% Q% f. }' n$ u3 LD.        b1||b2- W& `* H; [* C! B& W; [2 d4 w
E.        b1&b2) t2 x) E/ R) E1 D  ^8 u
F.        b1|b22 r; B" F" B/ x! @4 e
17.        Given: / C5 Q& F1 x4 b  M) A& Y0 }6 C3 _
1. public class Employee {
" f5 W* ~+ O& ^" E2.
. n0 t  [9 S" C  T5 _. R8 ]3. }1 z$ j( b  f9 _7 N& f6 _
4.
. a! D/ r% O6 y% u$ l, b. d  d5. class Manager  extends Employee{0 H8 h4 |  E! y: T7 k$ E1 ?4 o
6. }
% R; a  N5 O, J. s$ ~What is the relationship between Employee and the Manager?( U8 O6 C: R; Q$ E- F  T
A.        has a
3 p; |4 O3 G6 X2 e: k+ _B.        is a% U! ~/ h! K: C) a- y, z
C.        both has a and is a: T/ d6 p9 v% N. `2 w
D.        neither has a nor is a" N/ }& T: U4 c, x: Z$ R) z  l
18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?' j) D$ u5 [" j- ^" {) B
A.        BorderLayout! [* O' ^3 _) ?
B.        FlowLayout
9 n; k* k! X' a) A( q& B( |C.        CardLayout' v0 n. v' |1 K- c
D.        GridLayout! F3 B, i1 T3 a5 h
19.        Which of the following AWT components can generate an ActionEvent?
) D/ C! l7 x4 I' S1 }A.        java.awt.Button; U# j$ g) f6 o$ o
B.        java.awt.Panel
, ]; T1 J. o" q2 EC.        java.awt.Canvas
1 r; c$ {$ w  f) R& T+ L, Q# |D.        java.awt.Scrollbar9 n' x: O9 X. J/ Y9 ~
20.        What kind of Stream is the System.out object?
6 z9 s7 @* Q1 G( z. i) a3 Q( ?A.        java.io.PrintStream
1 a5 h; j* V6 P8 ]# \B.        java.io.TerminalStream& b% p! x5 g, s' H
C.        java.io.FileWriter
& T5 A, G4 W% v- v( pD.        java.io.FileWriter7 F! v$ I  n$ a' x( q4 _2 m. N
21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)( C* O7 r# ^! i8 c( v/ E" i
A.        java.awt.event.FocusEvent0 G; ]3 Z2 h' e
B.        java.awt.event.KeyEvent( D1 v5 P& c( u. ]
C.        java.awt.event.ItemEvent
7 F0 q2 ?2 q% lD.        java.awt.event.ActionEvent% G8 p& s# |" t+ o
22.        Which of the following methods are static methods of the Thread class?(双选)
: L/ B8 A5 M: wA.        sleep(ling time)0 i3 {: Y2 M/ Z( Y# k4 a9 p
B.        yield()
- w7 v: [! c5 u- gC.        wait()7 h6 [- j- E1 C/ B# |* n2 N
D.        notify()
8 Y5 w0 m5 a5 R3 k' I# B; x: C23.        Which method do you have to define if you implement the Runnable interface?
6 q7 u, Y" X4 J3 w( h' zA.        run()4 e7 u( Y/ p' e
B.        runnable()
# t, z% n9 [/ \1 u) PC.        start()
2 P3 H# F9 ?+ p( l! [" fD.        init()
7 ]2 Z' x/ H/ UE.        main()
( @2 g9 V) S3 i0 x, Q2 d( ]/ w24.        Given:7 K* I6 p( ?8 L. h
1. class MyThread extends Thread {
. q7 }5 a" x* k5 m& Z( o8 q5 i2.
/ E$ s* {" p  k' K9 J7 O3. public static void main(String [] args) {
' n3 m, L9 @0 l; q* r: K, Z4. MyThread t = new MyThread();
, c) `: N  p  @! a5. t.run();
* ~2 N1 Z/ S/ e% x8 d6. }" Y6 Y7 r, T2 z  Y3 P) J5 k
7. 5 T* j8 \/ B- O4 _) X: G' v, i
8. public void run() {* P, f5 q0 a0 y. C
9. for(int i=1 ; i<3 ; ++i) {
# M! I9 ^) U  y10. System.out.print(i + "..");
. i, W+ y5 ?( R2 V5 N+ o  B11. }' r; |0 ^5 R5 H2 C& k# K0 r
12. }/ u4 L( P8 X/ O4 o7 N4 k% S
13. }. `/ l* `# v4 i: U
What is the result of this code?C
3 u' v' V! h& x) F8 J: dA.        This code will not compile due to line 4
5 E% i. F2 u: mB.        This code will not compile due to line 5
) ~+ i7 ?$ V. O# UC.        1..2..
' g4 H  t: F. f. d0 o; ?D.        1..2..3..
, |( J  ^! q* T5 B0 C' f7 e. |4 x25.        Given a local inner class defined inside a method code block, which of the following statements is correct?- B/ ^/ ^: \/ ^- R& `; B
A.        Any variables declared locally within the method can be accessed by the inner class
" ?$ P* E1 E6 E9 X2 E% jB.        Only static variables in the enclosing class can be accessed by the inner class
4 D4 G  M! ]1 ?2 W7 [3 g2 E6 D( cC.        Only local variables declared final can be accessed by the inner class# ?0 n) d7 A/ r! z/ c% b# o
D.        Only static variables declared locally can be accessed by the inner class.2 |7 C: f: `# w. y

/ L% c9 g; ^( P( U9 O) o6 F8 ~; \" |$ C" U  {/ c/ ^. L

6 T' h  g# d, l; ]: A* z7 s3 ^6 W26.public class SychTest{
, N! Z4 D! P5 n! ]( C   private int x; - F8 K3 k# y, p) P" X+ R# |
   private int y; 9 U, w6 e6 i/ A2 u
   public void setX(int i){ x=i;}
0 {0 O3 @  |6 Q0 ?6 Y   public void setY(int i){y=i;}
3 r. y7 ^! Y4 s   public Synchronized void setXY(int i){
/ V) g) |$ F  P" W0 v4 e4 r& `% `     setX(i);
! f( x. d1 J5 [" D! ^: n$ c     setY(i);
4 O- Z& h: M3 [0 i1 F+ F  Y   } & ~! b) |2 z. Q# T$ e# x. y+ w( G
   public Synchronized boolean check(){
. B9 @' l2 f0 A# a& {5 V% e: y) G- N        return x!=y;   
: m8 c, R; ]2 U+ `0 _   } 4 @( h. Q! S2 Y. M
   } * @7 r2 }6 |- i) ~! @% q( ^
    Under which conditions will  check() return true when called from a different class?
4 L* A3 m/ Q, Q8 R" G. a1 ~4 \5 c   A.check() can never return true. : D. D/ I7 K" Z. r' o
   B.check() can return true when setXY is callled by multiple threads.
* v& g9 \% \3 u! ]- }4 _9 `   C.check() can return true when multiple threads call setX and setY separately.
% \; l9 n2 Q4 e* u. L   D.check() can only return true if SychTest is changed allow x and y to be set separately.
" ^, R+ z: B0 s4 F4 ?# H
4 T9 N6 ^" k* W1 q9 x$ o$ G. G27. 1)public class X implements Runnable{ & @) X1 {7 M" ]; c* E5 x8 o+ {
  2)private int x;
- h; d" Z& Y8 o" J  |6 i$ O  3)private int y; ' x% [: H& P9 X. s6 ~' E. d$ v
  4)public static void main(String[] args){
& J. I! l+ ]+ K  c; Q* s  5)   X that =new X(); 4 H1 v5 w+ i( F% o
  6) (new Thread(that)).start();
7 t' y& l7 `5 E' R( G) @# b+ q  7) (new Thread(that)).start(); $ ~- T) Y7 n# ?1 @9 J/ X- @2 s
   }
1 u) L) N2 G; X0 `" x* C/ \  9) public synchronized void run(){
+ v, O$ a% U" a' d9 V3 W  10)  for(;;){
% d9 ~/ x: P4 d6 q+ k% l+ L  11)      x++; 3 N2 p* T3 `' V* h3 o
  12)      Y++;
+ {. N: a  r; L  J  W6 i) R2 J; O  13) System.out.println("x="+x+",y="+y);
4 M7 m% j' Y4 K6 ^1 c  14)    } 1 Z  u( {2 [+ A9 H$ i% V
  15)   } ' a$ z; l1 j6 V" f, |
  16)  }   
& X, D; @* I& g    what is the result? ) q/ O; k, t. |3 C, S0 [) _+ y# s
  A.compile error at line 6 9 p% L* O% D& ^( M+ e
  B.the program prints pairs of values for x and y that are
3 i8 V2 e" F5 b+ j: f$ M4 @& z    always the same on the same time
" c8 L- Z; Y' U8 V1 }& @4 q" B+ o$ Q7 D% ]1 Q- ^9 P: M0 E0 W/ u
28.class A implements Runnable{
9 ?4 g  M( H) {% ^3 H8 \( _; Z  int i; $ C: x4 G( C% N/ }0 @& N
  public void run(){
* Y: A5 S: i5 b   try{
2 G; m8 Z7 g$ ^. K+ _) l       Thread.sleep(5000); 9 _! S+ N2 q$ n
        i=10;
) }5 \5 ]9 u! p5 q; o! i2 W       }catch(InterruptException e){} . O+ H8 J( b4 }1 Q2 u) F
       } ) ^# p" u, K9 ~
       } 9 F9 F, ]+ _7 [/ h
   public static void main(String[] args){
! a7 q+ p0 Z: [) I/ r0 z      try{
6 W4 z+ D8 V8 j% O+ Q  n         A a=new A(); ! F) X- a# ^  q' e7 f) A) _
         Thread t=new Thread(a); : F3 N( @+ V' {
         t.start(); 3 Y8 ^2 q+ _& q3 \3 _5 M: [: v! X
  17)
: d0 L+ B5 K/ L1 Y      int j=a.i;
7 q& s. A# \% e0 Y- ?8 I) d- }  19)
( h5 g( N. R0 X* w      }catch(Exception e){}
4 e4 {7 J1 z8 D7 y( T      } ( E1 T& W+ z# M: r( y: W
      } & X3 |. g8 G- k  r# j. C, `& m
  what be added at line line 17, ensure j=10 at line 19?   Q  C& W6 N7 s! V+ p
  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   
, L$ L+ U* Q  C  E.t.notify();  F.  a.notify(); G.t.interrupt(); 7 m9 l& b3 q  e0 ]( Y$ ~
29.1)public class X{
% W5 g" G  J* j0 c" I  2)    public static void main(String[] args){ . t+ B1 H' N- x0 L7 l, O
  3)     String foo="ABCDE"; , N6 s8 [/ [1 w
  4)     foo.substring(3); 3 W0 N" P$ ]5 Z
  5)     foo.concat("XYZ"); 3 Y* @6 W+ ]  Q3 N8 L9 c
  6)    }
2 `4 }7 X! a" n# E9 g$ R5 B5 O0 r$ u  7)   }
; `( @; ]. q& F: N0 Q) o  what is the value of foo at line 6?
3 k2 F4 c1 q/ v; _9 A* Z30.  public class Test{
# ]4 N1 C6 k3 Y, i   public static void main(String[] args){
7 k0 c* T9 ~& i5 s2 h  L+ i" i9 U   StringBuffer a=new StringBuffer("A"); 7 x. x2 V5 y; h7 V% F+ v
   StringBuffer b=new StringBuffer("B");
; S" m* ^% t# N/ L" E' B   operate(a,b);
; d( E% G1 l1 e6 ?4 i1 P# B% `   System.out.pintln(a+","+b); * g, l( Z; {: n$ `* Y4 m) G2 M( _  p
    } 7 s- N8 L: G9 ?% G# R' [- J
   public static void operate(StringBuffer x, StringBuffer y){ ! |5 D2 e  z* K/ s2 Q
    x.append(y);
3 G! p0 H2 z5 O8 A$ [    y=x;
7 P0 d+ B; \: D( v- B3 e   } / g( O+ I2 @* ^( q  i
   }
! C: g3 g  v8 p8 R6 x4 T4 l8 y! V   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享' {8 }5 W2 c# i* y% {- l. o3 T
我已下载。。。。。
* M7 `5 D, B3 W  C8 U; O& c- ?特感谢您的大公无私
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-4-6 15:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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