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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题* v; \, E; A# w" h8 `( Z
1.        给出以下程序:
4 N4 }2 Y  x( h1 ~- H1. public class Colors {# E# x3 S3 v! i' n4 {9 Q
2. public static void main(String args[]) {
) ]2 ~1 J: |) I5 E3. int n = 1;
4 ~1 {( r. z2 G) [# E4. System.out.println("The Color is " + args[n]);
  \4 I' {; B( D& U3 b6 |5 b5. }
$ @7 e- i% b! _  {1 x6. }5 f* F. |' z) C5 h
假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”( Y' I4 {. {: E8 R, b" C( ?) W' ?
A.        Colors red green blue yellow9 J+ ?* Q$ l" T
B.        java Colors blue green red yellow
6 O+ J( f) m8 p8 R$ R; R  kC.        java Colors green blue red yellow5 N3 A; l0 g; D/ P
D.        java Colors.class blue green red yellow
9 @: o( d+ X6 UE.        java Colors.class green blue red yellow
# v- c) D! L4 T& k  \2.        读程序:
( N% f5 n+ j4 m! [- [$ ~. j1. public class Test{
5 u! q+ e3 v+ W" ?2. public static void main(String args[]){
* a3 O3 T9 T' |1 I" K( D+ n2 _3. char c = '\u0009';0 U) w& V% l( j8 f) @6 j
4. if( c == 0x0009L), e- C, n9 S& r! `5 U+ S% o4 [
5. System.out.println("Equal");6 @, u! Q( C! |( q; ^
6. else System.out.println("Not Equal");6 Z  F$ o& A0 G
7. }
# S) g0 Y+ u7 h  u1 g8 \0 p; g9 x8. }/ C8 d7 }5 c$ Y- W2 v# t1 X
当编译和运行该类时,将会发生什么:4 V$ r# G2 e. T7 z
A.        程序因为第4行将出现一个编译错误
: M5 c  d9 s) [% J" NB.        程序因为第4行将出现一个运行错误
% K4 R) a# W5 @2 y# ~2 q" X# FC.        程序因为第3行将出现一个编译错, R4 G$ Q7 D" d8 _: k
D.        程序输出”Equal"/ d0 y$ e& A5 T/ E1 f/ ^7 N0 E
E.        程序输出"Not Equal”2 a& M7 c9 L, H* K7 b6 e
3.        读程序:! O( p3 ^) ^, R& Y- y- x" i
1. public class StrEq{: e3 h. I) N: w8 T+ I4 t9 m
2. private StrEq(){( ^; G4 p* o$ N9 Z/ E9 t( z
3. String s = "Bob";# @( \# m: o3 p" v5 |& P$ S
4. String s2 = new String("Bob");+ J( w6 z" |+ K7 N
5. if(s == s2){
" F' {4 T+ P8 l; x% f- y6. System.out.println("Equal");
, |% Q( {6 }) d$ p7 V9 \7. }- ]5 k; m  S  R: y' b. d
8. else{1 Z$ R5 g6 C+ O  Q  m0 Y
9. System.out.println("Not equal");4 C/ p& q4 _# C( H2 N& F6 E
10. }
( k) b; P; B/ b* C& v8 I# E11. }+ W; Y7 A5 h/ F6 Z0 u
12. public static void main(String args[]){7 q4 j5 {3 T' |) U9 Z( ^
13. StrEq s = new StrEq();
6 M/ }+ n9 m4 G14. }! ^( H. s- P# D' S
15. }7 H# m$ U* q' G" |. x
当编译和运行该类时,将会发生什么:" X" E9 O. Z8 s
A.        程序能够编译,并且输出“Equal”. P; ?( M; p/ V. ?6 Z, H) H
B.        程序能够编译,并且输出“Not equal”% J  b( o! n% R: O9 \
C.        程序因为第2行导致一个运行时错误
0 p+ z" G- L0 P% x8 x, f8 bD.        程序因为第2行导致一个编译错误
6 F5 g+ m8 H! k: |3 g4.        以下那个赋值是非法的:
5 |1 [# v* |! `& ^! nA.        long  test = 012;
% c4 @8 t- ]; ]8 {: T5 j  BB.        float  b = -412;" t& X  v; M) R% T% X3 T% Q$ g
C.        int other = (int )true;
; E  F; N9 y+ f6 t. r, XD.        double d = 0x12345678;  Z2 O+ G# t4 Q4 H7 j
E.        short   s = 10;
4 ]1 {4 f: _0 h- Q5 s1 b5.        读程序:- B! o, H% D2 L, |& u9 }
1. class CompareString{$ R+ e! M# W2 c' {: S5 x
2. public static void main(String[] args) {! ]1 _( I8 `1 B' L7 m5 X+ @
3. Integer x = new Integer(5);
! m' y  V$ h; |- e8 N' H' r4. Integer y = new Integer(5);
2 E; T! T, z& U# a4 ]/ A5. Integer z = x;0 p% o5 b4 s2 \, i8 N2 f
6. if ( ______ ), T8 F: j2 C( t  q( B7 z- r) s
7. System.out.println("true");% f) k* [: B1 G! P. A" X1 s" g
8. }
  L- V: k+ y! G9. }7 v& g. Y- N# }( z9 X: {$ x3 V$ s
以下哪个选项填入第6行后,不能输出true:
4 w- D) a5 M9 [/ }: Z4 |7 AA.        x==z$ Q( ^/ b1 U9 q
B.        x==y
/ U! ?0 ^( Q7 tC.        y.equals(z)+ e* n/ I! q" s8 G# y% }
D.        x.equals(y)
$ d' K3 O( t. i( C) G! P) }6.        读程序(双选):9 W9 \6 {0 r' c+ y0 E7 S
1. public class Declare {
/ ?4 o3 X# ^1 d+ `6 a7 E2.5 s. s' w( m0 O
3. public static void main(String [] args) {5 @( B; g' U* z0 h# Y
4.* _" T# `' l8 N% m% Y
5. System.out.println("The variable is " + x);
) X5 A2 u: D( v9 ~3 d8 M! r: y8 g6. }2 f* M# B, c3 a0 ?7 l8 o1 E# H
7. }
+ h- y' x- O; j" a+ L2 H1 `以下哪个选项中的代码可以使程序编译通过, a/ D; p( G2 S- `; b% a& U7 b: U  v
A.        把“int x;”放在程序的第2行0 B& P2 D6 Z' d$ O+ K+ s+ l
B.        把“int x;”放在程序的第4行1 S) x7 a5 a( @& T
C.        把“int x=5;”放在程序的第2行
; U9 t6 ^3 |- x( w0 ND.        把“int x=5;”放在程序的第4行
# c7 c! B" x: R/ T0 O2 B( H9 }E.        把“static int x;”放在程序的第2行
: b3 X; W( M  X
# M- t! m4 ^4 ?3 ^0 {8 U8 A# d6 X8 ?8 {, z% x: @

2 h3 F" t% s# L9 T* q% L8 b. T1 v( d7.        读程序(双选):$ h1 |6 S; T2 g/ Y6 h( F( A$ h
1. public class Child extends Parent{
( O; \2 [! u+ l( v/ X; n1 \; r2. int a, b, c;
/ l" k9 k  C5 S8 w3. public Child(int x, int y) {
* @# n' W" O1 n7 S, @9 G' E4. a = x; b = y;
6 S) |& ]2 l7 O) ^! y2 D: V$ S5 S5. }
# {# B  X7 S/ X. s0 p& S, L6. public Child(int x) {
! L1 }3 {' c8 P" Z7. super(x);( E" y$ o! ]4 S, ]) ]- ~2 |/ n
8. }
9 }4 H! ]5 q4 r! B; z" D. x) _9. }( Q8 \% `: R+ N8 v0 c1 c& _" Z# T
为了能使该类编译通过,下面那个构建器必须出现在父类中:
4 f3 t. J1 A8 {8 {A. public Parent(int m,int n)1 @! |3 O6 b) Q' _. G4 M0 \
B.public Parent(int m), G+ Y+ ?, d1 q) q$ I
C.public Parent()
% U4 ~  t, \7 u8 E% u* ID. public Parent(int m,int n, int o)1 B0 W# r. U% r2 g
8.        读程序:
+ |% m* |. r! b# ]2 z+ q" W* [1. public class Derive extends Base{
+ ?# m6 o. @1 \% r  N9 V% H, N2. public static void main(String argv[]){: R" k/ n0 _2 M2 I
3. Derive a = new Derive();) k! t$ R' `! }% h! K+ i: ~2 p
4. a.method2();5 |) Y1 b8 U% K1 k+ c# [
5. }
! \" `; F$ x/ k1 K9 L& c6. public void method1(){0 [$ x2 n2 f7 T4 `  `
7. System.out.println("method 1");$ _2 }  L: B( C: m2 O
8. } / _4 ?: s. X3 K" T( }
9. public void method2(){* R6 f. I: e1 i  p
10. method1();
$ k! g: D; ~% l& r! l11. }, o/ F: r  H+ X/ Z8 N; Y& [
12. }
/ c6 J" W8 X* v' u1 Z  [  I8 h13. abstract class Base{
* F4 W! ]+ V/ E7 y) w2 A/ s14. abstract public void method1();: E/ F; _* Z6 [4 M; E: s
15. public void method3(){3 l& c, ~( e- w0 C5 ^+ s7 W4 e
16. System.out.println("method 3");
) l) _9 ]! X8 |& h17. }; [% ]* N4 f+ {. z' e0 v# f  B9 o
}
; Q: d0 ?4 `; S# o3 A当编译和运行该类时,将出现什么:$ S4 h7 p( W9 h# q0 ~' r1 \2 L
A.        程序输出“method 1”
+ t. P# R' \# A  T* w8 a3 Y5 BB.        程序输出“method 3”" v/ _; f7 I" h" }" a% S
C.        程序因为第15行而出现编译错误1 ]5 x" C& N; r7 e+ Y- x
D.        程序因为第15行而出现运行错误7 R$ p8 K* j& e" e, k
9.        以下哪个接口的定义是合法的:
: I6 m  U- y/ ?* k$ U5 r8 xA.        public interface A {int a();}" D5 }; Y- g7 k; [
B.        public interface B implements A {}
7 w+ ~$ I! N) W6 B" lC.        interface C {int a;}
+ u) |2 Y+ a# b4 l: o- @4 ]D.        private interface D {}
! k* k" y+ N: y, M4 |' v+ o# S10.        读程序:; ]1 F( i/ f" ^0 J2 |1 q
1. //File SuperClass.java1 S* h4 v) ]2 c- q: n
2. package MyPackage;9 n, ^" t9 s% G+ V% m
3. class SuperClass{
6 Q: Z5 A2 {; S, ~% d6 h6 W) h1 v4. void myMethod(){
0 M: u# d4 f/ X% G7 D: z5. System.out.println("SuperClass");
4 J! K8 |* M4 Y6 P7 k; d7 x5 d6. }
5 C1 [4 {) a! |3 p4 H2 D7. }  g, l' x- w) M% T
8. //File SubClass.java
$ n$ u+ L2 J6 b# _( a( i9. public class SubClass extends SuperClass{
+ r' v: H+ Z& M) f3 X+ m10. public static void main(String[] args) {* `$ |; U* ~4 W% v) \
11. myMethod();' \0 r! A5 h; R9 x1 v/ y6 K5 x
12. }
# e: t& m) X' L- u13. }, j. j7 z# d' k6 X8 d, [
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:1 z1 C. t% q( J$ ]7 a& l, a
A.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”. j) W1 y" W( I  p; i  z2 R( d
B.        两个类都回出现编译时错误
+ b# p  g2 U7 JC.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误2 m! T8 ~8 m: I# C8 T6 \. W
D.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误; n, @8 q6 a  s* Q
11.        读程序:
( M/ Y; H: Y- z7 @2 a+ G) t1. public class Test{% I! `1 g3 k6 w8 w: v9 L# C0 w- A
2. public static void main(String args[]){9 x5 p$ J+ f" t' \
3. int[] i = new int[5];
+ E5 o% c: g- m, e) |0 c' q9 P4. System.out.println(i[5]);
3 |" U. e6 c! a9 J1 t5. }* a+ }) ?; m2 \/ L
6. }
, R" j2 ~8 f" |$ s2 q5 m当编译和运行该类时,会:
+ u+ [* z  s5 O* Y0 C2 DA.        出现编译时错误/ ^0 `; P+ C) P  K( F- }5 J
B.        出现运行时错误
2 g# w; f6 |7 H* E; ], O* B* zC.        输出0
: m! E, R' a, G2 R) z. iD.        输出null: s0 _2 P+ c& H$ B3 ~
12.        以下哪个选项是正确的数组声明或初始化:
/ {/ C, R& r# E) Z' s$ {6 C/ }A.        Array sizes = new Array(4);+ H. \. x$ o% Y1 k! |- V, U
B.        double [] sizes = {1, 2, 3, 4};' o' R# T, {7 ~: @
C.        int [4] sizes;- `7 x! p- K8 P( g
D.        long sizes [] = new [4] long;2 ], O6 |4 X5 V# y3 i
13.        读程序:1 P: d. B5 Q$ s9 ]2 `1 Z; Z
1. public class Initialize{
* M0 g% N7 q" `. a2. int x = 200;
3 e$ C0 o1 U0 z% o! W" O3 r3. static {- H+ z6 |' Q1 U1 p; Q
4. int x = 100;, W: N+ G- b% O
5. }
- A, M* [; l( R( a0 S. F& l6. public static void main(String[] args){
1 {& }- p9 H7 Q- g1 p- K7. Initialize init = new Initialize();; ]# D% ]3 h" m
8. System.out.println(init.x);$ Z5 f4 Z1 T% h5 [/ \% j
9. }
* Y! X5 G7 c6 P" @* y; l( E  |10. }8 F& o, j. E; m( J  |- U* Y
当编译和运行该类时:) D9 O' P' E- X3 i+ A
A.        程序因为第3行产生一个编译错误
. c3 N4 ~, S2 J" o! F3 `! t0 U* H: a; ]B.        程序因为第4行产生一个运行时错误/ g9 H, q, m1 O9 @0 t% }7 s) `
C.        程序输出100
% ]4 n2 x0 v' O: j% i( jD.        程序输出200
- M$ t1 W9 Z* V8 y14.        读程序:! [- ]7 P9 k- w
1. public int abcd( char x) {* z9 F& ]0 \7 s' u( j
2. if ( x <= 'M' ) {. O( Y2 z; i  y, G; n0 G
3. if ( x == 'D') * n1 q" x2 T" @8 H4 e: q4 c! C; Z
4. return 2;
) v6 V* ]8 n% Q8 c5. return 1;
0 k' q4 K% l% g' h  [6. }  j$ X) C: z; {
7. else if( x == 'S') return 3;
. w0 ^, |/ h# L# j8. else if( x == 'U') return 4;, m+ B. O5 v2 k' H
9. return 0;& t: Y4 a: h) |  F2 L& T0 k$ |0 J
10. }
! {# A1 s* R! G- B9 d0 B在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1, m: |$ [, ]8 h
A.‘X’9 B2 J. z% e  j" {: h9 _! O
B. ‘A’+ p7 q" W3 ]4 q, |
C.‘D’: Q- q2 @- o/ M. z& g- E$ u
D.‘Z’5 G& R" z% x0 w, x
15.        读程序:, G& {! o5 v0 j" H) M
1. class TryTest {
, h4 u( q7 e5 m+ l5 Y2. public static void main(String[] args) {
+ Y) q7 J- @% D* l' J$ R3. try{
: K7 I0 x6 o7 _5 `: }8 N9 h4. System.exit(0);
$ e! i5 n1 y# V: t6 q- v% b( p5. }, v6 t. n+ N- y; V# z
6. finally {
. Z! T& J0 N8 k( p; S; z$ C7. System.out.println("Finally");
6 s1 T7 n$ `8 F6 s6 T6 u; r6 r  R8. }
6 F0 y/ v' w6 j# a5 s& O$ W9. }
8 |5 n* e5 X) D9 H9 ^" _$ q4 s10. }
1 B- p" o& _; U/ P3 q0 v0 ?  D当编译和运行该类时,将:) K' S; Z* [) r) E
A.程序因为第4行出现编译错误: t$ s$ D' A) k6 \  `* j+ P
B.程序因为第4行出现运行时错误
3 b( j0 @" i! D; r0 t' lC.程序因为第6行出现编译错误1 @& n' _3 ^) k* b
D.程序因为第6行出现运行时错误# V- [% r" b' E" h: B2 c
E.程序输出“Finally”
6 M5 Z$ f6 Q4 Y, C3 C; A/ QF.程序可以运行,但什么也不打印8 `  s: s% j, ]0 e

% K5 H; l7 J% K: M8 K, i16.        Given the following variable declarations:
+ G9 M0 m5 s  f' ^. L! ZBoolean b1 = new Boolean(true);" M/ R" Q4 [8 w3 T
Boolean b2 = new Boolean(true);$ u* e& L8 N) @/ C8 |/ w7 O2 r3 n+ `
Which expression is a legal Java expression that returns true?
* `) N3 D4 Q1 y( `) FA.        b1==b23 I% S# f# C) X! s5 o; |
B.        b1.equals(b2)2 Z& a" K! s; A8 S# T! K! C- v
C.        b1&&b2
8 i: u' v( \5 A# kD.        b1||b2  ]+ z% i# y2 q7 w5 W- h/ @7 D
E.        b1&b2
. a4 ~. b# F% h% ~* B% NF.        b1|b2
9 b, U4 W! o% Q5 Z3 M! I$ o. k17.        Given:
4 L+ ~) }) a; B( p5 j1. public class Employee {
+ k( j! N. z' m1 h: J, ?2.
) a$ m8 `4 h" ?4 i: B0 ]6 r2 t3. }( L2 w3 f: r" R: [, }. w' G9 ^; G) g# Z
4. / u' a4 s3 D/ p# R! p: d
5. class Manager  extends Employee{
" H9 z+ Q$ p! I* l7 _; }6. }' _# k$ s7 Y; j& U
What is the relationship between Employee and the Manager?1 y- i  N/ z2 N1 T% ]( g
A.        has a* `2 [: G( n: B. p
B.        is a. w1 b: n/ Y& ?9 e' G! `* H
C.        both has a and is a6 @0 f& K0 U2 g7 y
D.        neither has a nor is a
2 b% Q; W' A# h4 _3 n. o18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
2 H$ P( U4 e4 g  dA.        BorderLayout  J! k6 v% R$ |- n6 o4 T$ w
B.        FlowLayout$ T  k* H% z" z- S+ y8 d
C.        CardLayout% O+ `- T$ x9 X9 g# w; u8 W
D.        GridLayout" X/ A( ]/ e/ m9 B9 V* L
19.        Which of the following AWT components can generate an ActionEvent?' h/ |- X$ L8 ~) L! U7 Q/ E' u& r
A.        java.awt.Button! j2 r5 S0 o- T. X" a
B.        java.awt.Panel
- Y/ d4 H$ F+ oC.        java.awt.Canvas+ t, y5 n5 m! c6 q2 F
D.        java.awt.Scrollbar
+ A7 ^3 X- N! L1 S2 L. s6 }20.        What kind of Stream is the System.out object?
! B+ d/ |+ `$ i+ o/ i+ d& pA.        java.io.PrintStream
: ~9 {- b' M+ CB.        java.io.TerminalStream
2 u+ s; n* b/ Y2 M3 n8 y9 }! ~C.        java.io.FileWriter5 h5 P3 L8 \1 Y( [0 g; T( ~* o
D.        java.io.FileWriter/ [. J' x+ E# f+ P; O+ L
21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)/ ]- `& }- n. K" y0 D
A.        java.awt.event.FocusEvent
9 b, ^7 |$ U" j+ ^B.        java.awt.event.KeyEvent
; Z  b" o6 Q1 \$ M) PC.        java.awt.event.ItemEvent+ p, v# m3 X1 e  p
D.        java.awt.event.ActionEvent. }' q8 J2 @4 d& s3 z! O; t
22.        Which of the following methods are static methods of the Thread class?(双选)/ A- h$ Q3 C8 v8 u
A.        sleep(ling time)
" r& w6 {0 B9 r" b7 G: KB.        yield(), R. C0 ]0 H* `0 r! _) l& K
C.        wait()
1 ^) l0 _' c7 r0 Z9 J; s4 A# `2 tD.        notify()
+ X! `0 Q! r) u1 K23.        Which method do you have to define if you implement the Runnable interface?
0 K# @, `1 y/ z. T% bA.        run()
, t- T' C0 x- }B.        runnable()
! F) E1 e3 S5 L/ E# p) R# I4 c/ SC.        start()
# d; f+ S! O- U; r5 d4 g; UD.        init()
4 q; d- T2 D" j4 E: c" P* kE.        main()
$ H. H7 j) a  a0 Z& z$ I24.        Given:
3 B: X0 H+ J6 u8 ]6 h8 O/ {1. class MyThread extends Thread {
! E+ I4 D7 x: g8 w; }" d2. % G0 Z" x0 m# n; o1 [
3. public static void main(String [] args) {
+ r& D. }9 |, u* V8 I- Y& k4. MyThread t = new MyThread();2 R; u2 }2 v/ b/ O: q- ^
5. t.run();
# }* U2 M+ y  a& v- ^& l( |* u6. }
! F7 J# D9 O. o! ^$ l  G7.
' x3 O. f9 [8 g1 i9 L8. public void run() {
. V; F5 @* ^( @7 O9 x9. for(int i=1 ; i<3 ; ++i) {3 D8 R! m* ]+ E
10. System.out.print(i + "..");
# }% G" M6 j, }5 e0 C11. }$ I4 f8 ]! Z, B% s( V
12. }
! u. M  G, S+ `- p: s+ l6 {4 L13. }; G/ B0 D$ Z3 o! `9 i& B- c& H
What is the result of this code?C
1 J1 ?9 a( z! ~" i% N% ]  PA.        This code will not compile due to line 4! `; k  {8 w% A8 g- ]3 @( ?
B.        This code will not compile due to line 5
/ s+ r; z% v, {  V' M- ]C.        1..2..: L; y( w7 |( Q% C. S# a: a
D.        1..2..3..1 N+ W$ J: n$ {: V+ s! ~
25.        Given a local inner class defined inside a method code block, which of the following statements is correct?0 I2 n9 ~6 E1 ~9 H% D- U' ?0 B
A.        Any variables declared locally within the method can be accessed by the inner class
. `4 R1 m9 e8 `6 I6 V- vB.        Only static variables in the enclosing class can be accessed by the inner class
7 G, {$ v5 I( ^2 PC.        Only local variables declared final can be accessed by the inner class
/ W7 N% n  i2 `) q, ^5 aD.        Only static variables declared locally can be accessed by the inner class.9 [" f1 D4 d4 W& J+ W& g7 d
# z6 q; h" @. h6 W
6 `6 X" l) r) R

2 \$ C7 A9 y0 k% N# s26.public class SychTest{
) H- W$ X$ W4 q! B   private int x; % R' W3 [* C! Q& W8 i# q
   private int y; " n- I3 z, `6 A, ]
   public void setX(int i){ x=i;}
2 @- [0 j2 k$ J6 v6 O4 j   public void setY(int i){y=i;}
( v4 M* }/ b" j+ O   public Synchronized void setXY(int i){ , m7 w8 }- G) U. n) e% d9 r* P# a5 }
     setX(i);
" c+ F  c: B2 n; d     setY(i); ; U3 c  a3 y: s6 M- l# q
   }
! @( L9 m3 P& W* \   public Synchronized boolean check(){ - I* C1 k, a- s& e2 ~0 ^. m9 N) \
        return x!=y;   
! i2 V( M# m; R   }
  U* g6 b  i! |0 _  {   } 2 d) M/ Q, b( t: ?. \2 n; U9 m
    Under which conditions will  check() return true when called from a different class? * b/ G+ a8 m4 f6 N& k
   A.check() can never return true.
- q+ ?. O3 i% h4 U7 M9 d) F   B.check() can return true when setXY is callled by multiple threads.
( T; e- Y; F5 N  Z   C.check() can return true when multiple threads call setX and setY separately. % L" [2 z1 h& c7 b0 m6 ?5 ~
   D.check() can only return true if SychTest is changed allow x and y to be set separately. ( D+ K/ Y7 k6 T; n, }. ?% `, t& t4 {

- b+ E& K! J8 a! J& \& y3 y3 _7 T27. 1)public class X implements Runnable{   Q" o# H% ^5 T- o9 p! A3 ~
  2)private int x;
) p  N! Z9 u& T% S! V' L6 T  3)private int y;
5 z4 y# \5 F( O: b2 G% H: ]  4)public static void main(String[] args){
9 t2 s: K7 u% l1 V  5)   X that =new X();
0 `/ P8 j: R" {  6) (new Thread(that)).start(); : P3 l) ^' K1 N. e" F6 G( }2 C
  7) (new Thread(that)).start(); 5 ~. T$ F" l; `2 E, x) b$ i8 l0 Q8 b& q8 [
   } ' A1 q8 H, b( R1 |& a6 `5 J& q. ~
  9) public synchronized void run(){
; }( L1 ^! }' J; S, p7 S  10)  for(;;){ - B7 h2 j* h& G. e2 ?
  11)      x++; 6 m1 N* C/ Z- {
  12)      Y++;
9 @0 l% A+ k9 K9 H* ~9 }9 m+ T+ j  13) System.out.println("x="+x+",y="+y); * Z6 `4 L! \; `0 d; L) I1 l
  14)    } % I0 H3 |4 e- F# [
  15)   } . h* O, ]7 G+ E. I0 u/ b
  16)  }   
% D$ s$ a% n0 X, ?    what is the result?
+ _7 [$ }* X, h& z  A.compile error at line 6 ( G9 b$ k/ U) [3 m7 [" c; G+ s
  B.the program prints pairs of values for x and y that are
1 @5 a& G& |1 v$ J, u5 Y0 |3 W    always the same on the same time 0 k9 x% r& U9 C5 w4 T
; m4 G; `* u3 T! u0 u9 M/ Q9 B
28.class A implements Runnable{
% M# a$ f( N7 @! _3 s  int i;
2 `7 ^6 V% |# p) t6 _  {8 c, l& V  public void run(){ / E! T" A& }. o! Z" ]6 Z8 R
   try{ ! h0 ]' Y# R- [. G
       Thread.sleep(5000);
3 a, ]- t4 z' _: r. m" ^* g        i=10; ( l3 C1 _6 z1 A- [+ x4 x
       }catch(InterruptException e){} ! z9 r, h+ a5 B$ h
       } 3 C3 ~2 m* g( Q# Q2 G& J
       }
2 M6 I' t# N, t6 Q; a/ K   public static void main(String[] args){
4 K  s% q, W% N      try{ 5 q. _8 U# S1 g
         A a=new A();
* S. V( i+ u$ D         Thread t=new Thread(a); ! P2 Y- B" b- g* t2 i& }, M. a
         t.start();
: V6 l9 T$ o) x6 j0 v1 O# l  17)
8 c* P& h2 D" {0 E- Z+ P% B* s" P      int j=a.i;
, }! C+ Z. V7 M6 E  19) / G# h! h) Q% \# i
      }catch(Exception e){}
& ?0 N+ {$ y: r% ~( ^      } 3 m& N8 A; f, n8 |; m! W! s4 ~
      }
+ @7 O6 O" ^( @8 N( R- G" A  what be added at line line 17, ensure j=10 at line 19? . V& e) X, \$ A* O4 W2 d
  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   ) @1 L1 ~7 U6 x4 M, s
  E.t.notify();  F.  a.notify(); G.t.interrupt();
/ g/ c+ o+ s/ B& c; [; @29.1)public class X{
6 a4 q! r0 T: A, }9 e+ j. k+ L  2)    public static void main(String[] args){
  K9 d+ |; G' }5 ?0 m4 o# p, @' C  3)     String foo="ABCDE";
3 a0 ^, s; t, H0 |: \# L  4)     foo.substring(3); . V2 D6 h( S; q1 j; X
  5)     foo.concat("XYZ"); 7 ]/ _4 [( Z/ h  c: _/ d9 M( t
  6)    } ( |: K9 O' p! ]
  7)   } : P6 K2 B9 r! u# U# Y9 ^
  what is the value of foo at line 6?
0 @  Y/ k' A& S* q- [& w% f30.  public class Test{
' f2 R& K( h6 k: w8 L$ h   public static void main(String[] args){
- |4 r' z; G6 O! S. D   StringBuffer a=new StringBuffer("A"); . t* ^9 Q# e. ?
   StringBuffer b=new StringBuffer("B"); 4 {4 S0 d8 ?5 s5 L
   operate(a,b); : D2 @' I6 G% e: E; ?5 R
   System.out.pintln(a+","+b);
1 q' h" x/ Q$ |" t  B3 B7 [    } * ?3 c8 p# I9 L" Q
   public static void operate(StringBuffer x, StringBuffer y){
& K% y' B5 p3 `' u    x.append(y);
0 I1 D" k* j5 ?/ h" I    y=x;
- J3 [) A: m0 R+ O8 ^   }
  w5 r. i/ {- O& |/ v+ U( o: s   } 5 G( x: u+ w: i1 M
   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享
& d5 @- i1 G" m8 B4 e我已下载。。。。。
9 ^" d7 w, h. D特感谢您的大公无私
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-1-10 21:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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