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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题
8 T4 _- Y+ ?! @  ^% ^1.        给出以下程序:
; @( I+ m# r0 T/ n7 @, F! s1. public class Colors {/ p4 T5 y+ {3 m
2. public static void main(String args[]) {- |7 u) a0 C1 ?9 ]
3. int n = 1;
% N& P& }$ e& S5 T  F4. System.out.println("The Color is " + args[n]);" r% H4 ^5 z; P0 k. M7 U
5. }
/ E) [* `; t. N8 E6. }
  A, P/ v+ C5 J4 P/ ^, Z假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
) `/ g' Y: R% Q$ O; @A.        Colors red green blue yellow+ x7 g& Y1 ^0 p' u" j* o
B.        java Colors blue green red yellow
. \7 z3 I, \0 O% z1 h) }& IC.        java Colors green blue red yellow/ ~' ~' R3 M" |) W2 L+ h) E0 m
D.        java Colors.class blue green red yellow3 u5 v6 ~0 `2 d* o; d
E.        java Colors.class green blue red yellow
, e: m) H9 C5 p7 y2.        读程序:
6 `* p( ~* {& u7 \5 d6 f1 Q3 {- j1. public class Test{
6 [7 N$ |# W* E: G- A5 @- d* J2. public static void main(String args[]){# m( Z$ I2 F+ `1 Z1 b
3. char c = '\u0009';# u, |; O) q; E% j
4. if( c == 0x0009L). ]2 ~# E4 Z5 Z- J, P& f& M- z: p3 o
5. System.out.println("Equal");
- M/ b& O! b, r6 W+ b6. else System.out.println("Not Equal");
9 x) @, g) p3 \# G' Q- s# W# n7. }
% \3 ~% I0 a: p8. }& ~$ e! l! k9 F8 r. Q
当编译和运行该类时,将会发生什么:
+ W/ I5 y% ?2 uA.        程序因为第4行将出现一个编译错误) h; i0 H% ]/ S( O# v
B.        程序因为第4行将出现一个运行错误
4 y5 {3 T% B- ]  B) k- U2 UC.        程序因为第3行将出现一个编译错
6 K" V3 w: @' k9 M2 HD.        程序输出”Equal"  H- C0 g, X7 D, l
E.        程序输出"Not Equal”
- |; ^. }0 U$ [3.        读程序:
; i; b4 z! o; o, ^- N8 W1. public class StrEq{( `' h& e% Q8 i$ o7 D0 j
2. private StrEq(){
0 u5 {6 r4 {" H1 j6 H& \3. String s = "Bob";
8 {5 j3 y( t3 o! G$ @4. String s2 = new String("Bob");. @8 g7 ?' l4 q5 h% ?& A' b9 h
5. if(s == s2){/ Q/ \( Z# v# @+ ]7 G! U
6. System.out.println("Equal");. k. r1 T" ~/ R5 t, Q. Z' v
7. }
+ V. ~2 e5 ^+ m. D6 C; t, z7 h8. else{
* a/ j: V2 D; i) P/ P& O7 G( }9. System.out.println("Not equal");
2 T1 m0 n+ S/ p# }/ {8 Z! I& b9 R* |6 w# F10. }
2 H( M6 u; o7 W# ^8 l4 |11. }
2 `% D; p! j0 L8 H% p/ m  Q6 z12. public static void main(String args[]){% n- ?% Y0 q+ w, [
13. StrEq s = new StrEq();
7 I+ ]6 z8 l9 O9 f; d, u6 ?14. }
5 y7 L7 a/ W+ P" O8 M15. }
  i* b+ i, t. \8 ^: g* Y6 H当编译和运行该类时,将会发生什么:0 k; i9 w' d4 [  u3 c9 B& V8 c; b1 P$ N
A.        程序能够编译,并且输出“Equal”6 Z: u6 F" d/ W! D0 c: H  P/ v
B.        程序能够编译,并且输出“Not equal”
% C! i6 N# T+ O" t" N/ cC.        程序因为第2行导致一个运行时错误- u3 B1 e) e9 v! K, q% P' ^. x
D.        程序因为第2行导致一个编译错误
) a& @" M( c3 V5 Q  d4.        以下那个赋值是非法的:* A6 c- I. ~3 X* D  S$ v% D$ _
A.        long  test = 012;3 z+ H# x; }3 S0 a/ T4 i* N
B.        float  b = -412;
# [3 E! ~) C% k/ a, e7 n8 `4 nC.        int other = (int )true;
! o/ s5 N! o) ~: lD.        double d = 0x12345678;
2 [0 n* \  h+ k, P) O, D( y( ^% XE.        short   s = 10;3 u0 {7 q' z; r( ]
5.        读程序:4 n3 v9 D# c7 _2 k* ~6 ]+ R! L- X1 R7 e# z
1. class CompareString{% a/ I% Z& H9 W3 T  L$ `, p3 M) I) ]
2. public static void main(String[] args) {1 @& }4 E( T# Z: e/ T: V/ V
3. Integer x = new Integer(5);* b3 N! }, y1 b  n( F" F
4. Integer y = new Integer(5);2 l( @6 K& I3 _/ |
5. Integer z = x;4 E* i# U! p% X1 a- m
6. if ( ______ )6 y5 L7 u' C- i
7. System.out.println("true");) ^4 y: z' A) f) L- ?/ a3 D
8. }. }8 g' m" F  X' `+ H' N4 y
9. }0 e( b' T  R9 _
以下哪个选项填入第6行后,不能输出true:
' _" \5 O1 w1 Z" k% Y8 i- ]( {A.        x==z
" o8 d- E8 S  P$ }( R6 |0 IB.        x==y6 x/ g5 O: R% E# j( \& [/ n$ M
C.        y.equals(z), Z! M& C: Y% O' Q
D.        x.equals(y)
' G, q4 ?6 j9 r1 c7 l( d$ n6.        读程序(双选):
- q6 y" |0 K7 ^4 ]  }1 b# e* E3 h6 l1. public class Declare {& Y9 {1 {  r! b! l, K% {7 r
2.
4 |- H& `& K9 h3. public static void main(String [] args) {
/ B' `6 ~; V0 T4.
' n' m* N: Z- H+ {1 v' \) H7 p/ X5. System.out.println("The variable is " + x);
5 S& U" e2 C) J6. }4 B6 q2 M" e7 B2 u
7. }
" N7 B  _$ [( w0 F% P5 d以下哪个选项中的代码可以使程序编译通过$ M( U% k0 s4 h
A.        把“int x;”放在程序的第2行
, W. D0 }7 U/ Y% g/ N3 uB.        把“int x;”放在程序的第4行
9 ]  h  j7 \3 e8 O: Y/ N& q! J, p1 VC.        把“int x=5;”放在程序的第2行7 N# Q" c6 k2 e% u) j
D.        把“int x=5;”放在程序的第4行9 x# B* e/ u/ `
E.        把“static int x;”放在程序的第2行8 Q9 Y; `# Y3 x
* g& z* j6 i2 R2 F% t

- o0 R8 b6 b; \% e: d. J% i7 p% x" b+ M4 J% a' p
7.        读程序(双选):
2 v: k. r* |* l7 F+ L4 Z1. public class Child extends Parent{
) z' v) U) G  _* L& F2. int a, b, c;) Z3 y, F* @' m9 M
3. public Child(int x, int y) {
, ]% q2 F5 Q% w' M8 L* R4. a = x; b = y;8 e! F8 z4 N6 [9 L; S) h- ^
5. }: Y. H6 M& l! c0 i/ i5 D/ i' X8 c1 N
6. public Child(int x) {
9 l* A. R7 n. U( n7. super(x);" f$ d+ ^% e1 e2 d+ q' m' s& d
8. }6 Z, Z9 q0 _' V% J  h
9. }
) i+ j* {& @7 `5 C6 o为了能使该类编译通过,下面那个构建器必须出现在父类中:7 ?: t0 m5 T+ ~1 J1 l! Q
A. public Parent(int m,int n)4 Y1 }; N  {6 h9 K/ I, d8 }4 S4 L
B.public Parent(int m): T; r/ F4 L5 l5 u
C.public Parent()8 s+ e/ T7 |3 _* f6 y! j+ O
D. public Parent(int m,int n, int o)6 h& h  o$ M/ q* K/ m* M
8.        读程序:
/ k2 U% W! N2 r+ G1. public class Derive extends Base{6 h' q/ V- `! `  ?- b4 `# n9 Q
2. public static void main(String argv[]){
5 O0 c( G- g4 z% e" h/ x3. Derive a = new Derive();, h3 U9 A# X, r. X% Q  V* A
4. a.method2();
& O* ~- A7 L3 Z/ |2 ^- L- q0 v5. }
0 ]2 I  U3 d6 H6 x/ `6 h  u6. public void method1(){0 |" ]# y( b+ t! d
7. System.out.println("method 1");; `8 a  E3 L3 w6 R* J
8. }
& e" r  f. [5 O6 }- z/ y9. public void method2(){
( H% V: Q+ S; J( ]( ?# q8 ~10. method1(); ! u& q- w. o( G. V
11. }
3 G5 U8 J# ^; E; J4 U8 |% |12. }
. z  g0 k- G+ F13. abstract class Base{( e% s& Z7 E, S+ E
14. abstract public void method1();
3 m/ Z# A. E# w2 |: `3 V15. public void method3(){8 _$ h. P% |; `* w; B# e3 c
16. System.out.println("method 3");* Z" R' ^. Q# `/ o3 v" U
17. }
; u6 A) J1 H9 L) p: H! \}
' g5 U$ M' ~3 T+ A3 U当编译和运行该类时,将出现什么:
8 U( x0 \( t8 `- z% M  VA.        程序输出“method 1”
5 O9 ^+ d# ?* X/ H7 ZB.        程序输出“method 3”
2 m; k6 |2 K# T# O; w) T% z" W8 g, ^C.        程序因为第15行而出现编译错误" |9 k6 o: \( }  d8 B0 w' J# y, S
D.        程序因为第15行而出现运行错误
% ]4 b2 h: D  v: o/ i- n( d9.        以下哪个接口的定义是合法的:
1 W% p5 j6 g, C: h, WA.        public interface A {int a();}5 L' b+ ?% @9 ]1 w' y& F
B.        public interface B implements A {}% \# e5 Y# p7 l# E$ q! N
C.        interface C {int a;}3 o. ~7 g) L& f9 h
D.        private interface D {}4 j9 u" I$ q( B: G% u  c1 q
10.        读程序:3 _+ O6 r9 O4 ^& K
1. //File SuperClass.java' ^- X( d) V2 I3 |2 d1 s/ t
2. package MyPackage;# I* ]; g' X3 `
3. class SuperClass{, P& I3 n/ D2 e0 c1 @( I+ O- E" x
4. void myMethod(){& D6 u1 w. r+ A6 d, t! m
5. System.out.println("SuperClass");5 P( p6 P' }8 A' p
6. }4 Z2 x4 D: B7 r) |$ |
7. }
2 @9 z$ _: ]  g# i$ w/ r/ G9 c8. //File SubClass.java
2 X9 Z; u; F" H: D4 f0 S  K# p5 K9. public class SubClass extends SuperClass{# r  T- S9 w6 D: @5 `) ^
10. public static void main(String[] args) {
" X7 m, r, Q0 Y8 ~11. myMethod();- \% X( B' u/ n
12. }; N: S% B/ z. V9 r4 U1 o4 T+ a
13. }
. n9 w/ D2 g& A# O  U当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
2 W, t. w$ e9 j# g( k; iA.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”* \6 C* l  {: `1 `. j
B.        两个类都回出现编译时错误4 K' @+ W$ T$ E" ]
C.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误2 j, G6 z* B; d
D.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误) u! t! T6 A1 t3 E1 ~5 \
11.        读程序:9 x3 ^" I. F0 u* ]
1. public class Test{
# f9 A! m" f) J! R# p% x9 \2. public static void main(String args[]){
6 E& w( F: Z/ ]# G, w" r3. int[] i = new int[5];- W9 e; d# @- Z
4. System.out.println(i[5]);
. }# Q3 V6 t& R0 |$ L: \/ B5. }  y- [, c& f6 O" l" d) y
6. }3 g7 D1 G9 z0 r& p3 C5 _
当编译和运行该类时,会:1 Q" p- Y$ Z5 ?8 j( `( f6 _4 U
A.        出现编译时错误2 H, x5 q/ P1 y" R2 x3 d
B.        出现运行时错误
2 @9 p) g4 g* T5 J, ^C.        输出0
; T9 j- G, n9 z# z6 @8 r8 iD.        输出null
5 r, s7 X; ~3 B7 M, }# Y12.        以下哪个选项是正确的数组声明或初始化:
, w4 ?5 D( ~/ g! KA.        Array sizes = new Array(4);
$ ?: l' q, |& q, g7 H6 eB.        double [] sizes = {1, 2, 3, 4};
5 j5 G5 l! C7 zC.        int [4] sizes;
9 T3 r- |& ^, S6 F3 CD.        long sizes [] = new [4] long;
1 j( H9 Q2 v1 ?* K' F: f13.        读程序:
3 F' \7 E7 k/ G; E9 a1. public class Initialize{" n. h/ y; u% ~9 U2 M# Z2 R
2. int x = 200;, Y, i- J) O% [8 ?9 w
3. static {" T3 p* Q2 h% f; T
4. int x = 100;
3 H: T3 s7 x6 y+ l. K* I8 e* _5. }
+ i  g- t- u: }: b9 \( S; L" B6. public static void main(String[] args){+ h0 `* T5 V- G6 s9 q0 Y- p5 M
7. Initialize init = new Initialize();' P) P8 H  x) J
8. System.out.println(init.x);
0 N. [9 T* S$ p0 y% x9. }
% [* T9 H! c7 p" K9 Z  u10. }
; M+ T4 n( R/ l4 g- ^% e当编译和运行该类时:6 n: Y4 ^% j% |5 l7 Z6 [
A.        程序因为第3行产生一个编译错误* }* x& H  F4 l) P
B.        程序因为第4行产生一个运行时错误
- n4 r9 E9 z5 V$ ~# a' uC.        程序输出100
0 U2 z$ {0 m& ], [& v. z+ bD.        程序输出200
8 \8 a- H7 c. _) {9 S14.        读程序:
5 j) ?, H  h$ a( B0 ]4 n% D1. public int abcd( char x) {% c% l4 @" t* I6 _2 E3 _; g: T
2. if ( x <= 'M' ) {
+ w) ]: e2 M# {: S( Q9 F# S3. if ( x == 'D') + i; k0 n& F" K2 r  e; `3 s
4. return 2;! v9 _/ F8 n% G7 K8 e4 @/ Y+ s- u
5. return 1;
. t$ c% A$ i% |6. }
7 R3 |1 q$ ]2 @. Z7. else if( x == 'S') return 3;1 J( s$ p: I( \: k) e: {1 y4 u/ k
8. else if( x == 'U') return 4;
* O; `1 E) {% r" _9. return 0;
: q. _: @1 n% ]% ~" i+ g+ B9 Z10. }
9 A0 D1 p+ V1 ^, _% ^8 X在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
( }! H6 t4 |' X6 B8 t* ^( VA.‘X’* G, d$ G4 p  f7 X: E. m/ e
B. ‘A’
5 `+ a; i3 n  t& x& oC.‘D’
" B  r! n' U- h% yD.‘Z’
/ @( h7 f  _9 c% ]15.        读程序:
& g2 y# c: O% p) X) _% H# O& T5 h% z1. class TryTest {
7 c) n4 D0 X. H% I. \. S2. public static void main(String[] args) {
0 w1 X1 s9 f: L( Y$ Z3. try{8 E1 n* i" K8 U, W" S  e
4. System.exit(0);
* Y9 K4 J7 I2 C" `  I5. }
, z0 O4 m4 V8 J& `% `6. finally {" q5 P% B4 K6 b  S
7. System.out.println("Finally");# ]( H+ C7 |9 \9 N( G" p
8. }9 W1 z! o) }+ P/ x- l) `
9. }
5 t5 S7 h2 g, y) Z0 T10. }
* h# ]" O8 C4 S  U  s- }# m当编译和运行该类时,将:
1 }0 {& ?. N1 h- I) E; x$ x! S  Z/ \A.程序因为第4行出现编译错误7 K% U6 F4 L4 W: o5 n+ J
B.程序因为第4行出现运行时错误4 J) ]3 b8 M* P) s. B, |
C.程序因为第6行出现编译错误- I( s5 l) r+ |1 A1 v8 s: {# w0 @
D.程序因为第6行出现运行时错误4 Q- D0 t# D% n4 y' o
E.程序输出“Finally”" n9 y$ \, I! K% e4 f  Z% X- I
F.程序可以运行,但什么也不打印. {2 N5 u3 r$ |0 T3 q5 O3 G( F
# ]% I3 G- q$ q1 e" K7 T& \+ X
16.        Given the following variable declarations:
( `  a* ~9 ^- Y  GBoolean b1 = new Boolean(true);
% f4 T# L: ~- f2 MBoolean b2 = new Boolean(true);
4 k2 Z2 D3 y. h0 C8 o& O. AWhich expression is a legal Java expression that returns true?
. h- [' }. |; LA.        b1==b2
# I8 w7 y* x- g/ uB.        b1.equals(b2)
$ Q2 B! c0 b! V/ c7 H7 }C.        b1&&b2
3 X5 W) t% U- i# W8 m# D" W  \D.        b1||b2
* l$ y/ ?7 Y1 t( eE.        b1&b2
9 O: M! A8 a1 s/ t" S# N$ OF.        b1|b2/ y; r& K! e4 ~8 T
17.        Given:
7 O% P3 S5 B4 h1. public class Employee {
0 ]9 i" [: ?6 Z& D$ X1 E% S2.
7 U+ U- C3 E; |1 a0 V' w4 Y; T9 X$ v3. }
+ W% C2 K3 W! ]- s: E3 ?5 @4. 6 P3 u5 S9 i2 r
5. class Manager  extends Employee{9 [8 R+ n' [4 z; s9 F" D/ e  ^/ i) ?4 \
6. }. J  q1 s1 q$ \; ^; {& }
What is the relationship between Employee and the Manager?2 \5 {# A  M/ ?  D) A* f: M
A.        has a
/ \3 k: z9 x7 A6 R0 ]& F3 A$ AB.        is a8 c+ g) o5 Y4 W* I3 d8 P6 f
C.        both has a and is a
) _$ |% u7 Y- k# TD.        neither has a nor is a
# Q8 A/ E9 Q. c5 y+ D18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
- H# R2 `2 S/ }. j" v0 K+ ?$ \A.        BorderLayout, u; }3 a8 s- i1 [6 n3 K1 E
B.        FlowLayout( @+ e  p6 d; a9 n6 u- i$ d; a; @
C.        CardLayout
. M8 j" n; Z4 J3 w. Z* bD.        GridLayout4 _% O7 e, T4 h  ]' q- _
19.        Which of the following AWT components can generate an ActionEvent?! z' b; W2 L9 c( p; i1 I
A.        java.awt.Button+ A9 P; S/ E( z+ h9 V9 v6 B7 S
B.        java.awt.Panel
4 a8 x6 P6 D7 c6 b. DC.        java.awt.Canvas% U7 J& e+ l1 @7 b7 s  h9 A5 g
D.        java.awt.Scrollbar9 {: H  @, b9 ^4 v, z+ ~( K* H
20.        What kind of Stream is the System.out object?, V9 x7 ~" [  \) |$ F
A.        java.io.PrintStream
0 @# R& C, e* N! G1 e* O4 w1 ]B.        java.io.TerminalStream& t6 T% Q- K: q& r* E$ ~
C.        java.io.FileWriter
$ U1 j3 e7 _' L' z' x1 K3 X" {3 H0 gD.        java.io.FileWriter8 y' a& R0 M- G, u3 k4 [
21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)
( T$ w9 }5 R  e! m7 _$ gA.        java.awt.event.FocusEvent3 u9 [9 L! z  |2 h
B.        java.awt.event.KeyEvent  A: g! o# f$ N2 `2 I1 o: N  |1 Z
C.        java.awt.event.ItemEvent
$ d: Z, s: m$ WD.        java.awt.event.ActionEvent
' _$ _4 q3 _- b2 |7 C! h22.        Which of the following methods are static methods of the Thread class?(双选)2 H0 l5 s/ _6 m  \+ D6 N
A.        sleep(ling time)
8 P1 h& V8 E8 a# J8 cB.        yield()( k/ }- {( A: d  N+ a
C.        wait()9 o4 T% h. m4 j
D.        notify()- o: x. S8 |  {3 m
23.        Which method do you have to define if you implement the Runnable interface?! ?7 d& v7 u7 R) c! \
A.        run()6 P; n; `' S/ s, X) k
B.        runnable()
/ W! a+ N2 o& |4 }8 C% jC.        start()
! V  D7 ^, S( X% Y# N5 jD.        init()/ T' F1 l* c8 p/ L
E.        main()
, z0 k1 d9 R3 I" D8 X7 `- O24.        Given:8 F8 q9 q' X# O  J$ u1 v
1. class MyThread extends Thread {
5 E" A6 M* w4 \4 K$ v2.
* _( `0 s- I( V4 b& m8 y3. public static void main(String [] args) {" x: q, D; K+ p- c* E
4. MyThread t = new MyThread();+ \) ~9 l2 t4 A4 b. D" k/ t: @* U
5. t.run();6 N- r7 e/ X( N0 n
6. }
( q) ]0 g) h# h' u6 u8 H7.
( C# z3 n9 b) q5 s8. public void run() {
2 f. e) M5 o8 y6 \2 Y8 }9. for(int i=1 ; i<3 ; ++i) {
+ Z6 u( s/ a- P* ~9 T10. System.out.print(i + "..");
1 \: K) J: S$ O7 x6 f2 I+ t2 Z4 O11. }
  X: `9 Z5 ?, G7 c5 ]& G12. }# J' e  \4 z: Y# E
13. }
8 d( v; I! p; xWhat is the result of this code?C! L. g, a. k8 d. y7 t
A.        This code will not compile due to line 4
2 U' t0 ?1 X: R2 OB.        This code will not compile due to line 5- E2 ?0 p9 T7 j5 Q
C.        1..2..
( H5 K0 x/ V, ~( Z6 mD.        1..2..3..
- a; \/ I. c' \9 ~) X25.        Given a local inner class defined inside a method code block, which of the following statements is correct?& D0 C/ @. l: a  a: T1 t' n! _/ Y& X
A.        Any variables declared locally within the method can be accessed by the inner class( i/ A% H' u. h$ K) s. ~) [% N7 ]
B.        Only static variables in the enclosing class can be accessed by the inner class
. C( b( f3 H6 W3 ]C.        Only local variables declared final can be accessed by the inner class
  H/ K4 i1 t% a% J4 XD.        Only static variables declared locally can be accessed by the inner class.5 o4 a9 d  @! r& M$ p

+ U& Q6 ~2 O3 _. W/ A6 O; p& i+ R; p, o8 }/ L& Q: c

. @' H( u( b, u7 D# t4 X3 N3 M26.public class SychTest{ 1 l. T7 |/ Y2 ?8 G  C
   private int x;
2 o9 X: }/ a* l3 f+ [/ I   private int y;
5 R, a$ b( \' L   public void setX(int i){ x=i;}
% u1 Q4 N0 i8 C* f1 K   public void setY(int i){y=i;} 4 r5 e8 e6 M0 W. {: q
   public Synchronized void setXY(int i){ : F3 Z, u& I1 B
     setX(i);
/ I1 W$ o/ r: j* M3 w9 b. e     setY(i);
8 N1 g% \2 n. Q; N1 m   } 8 s; l6 h  N% Z; n9 J; i
   public Synchronized boolean check(){ 9 {. {9 w; l! }' `0 s- {
        return x!=y;   
6 b& v8 G8 ^0 B: x0 K" z  [   } ( f6 S" e9 \) M0 b! o
   } $ Y' l) X. ]0 x4 H- y
    Under which conditions will  check() return true when called from a different class?
0 a8 T+ S" b) d, |7 t   A.check() can never return true.
( n, N& f& z( c   B.check() can return true when setXY is callled by multiple threads.
2 R% X  `# T% U+ G6 b3 s   C.check() can return true when multiple threads call setX and setY separately.
) N$ P6 O! |! v2 M' j( g4 J# j   D.check() can only return true if SychTest is changed allow x and y to be set separately.
& h) ?& B! H8 k6 g* P/ f$ k. E( {( L1 k/ k
27. 1)public class X implements Runnable{ . P$ Q; o: ~5 n2 y! S* [
  2)private int x; & `( L) h% O* l
  3)private int y; ! I5 a9 r. B3 m+ S
  4)public static void main(String[] args){ ' v" J2 {' q! S* T1 v; V* d
  5)   X that =new X(); + y1 u& E8 e8 \* j
  6) (new Thread(that)).start();
$ [. K1 ?0 O8 I; T  7) (new Thread(that)).start();
9 l3 y+ N) q& X5 H1 B; G   }
; I) {+ T5 A8 \" E  9) public synchronized void run(){
0 w. J+ E. I! X2 e4 W  10)  for(;;){ 9 K  L% O* u# b3 Z, I( r+ K+ P! Q
  11)      x++; $ ~! d5 ?/ P! m  e
  12)      Y++; 4 l5 j* O$ u8 v, Z0 j6 t. E/ Z
  13) System.out.println("x="+x+",y="+y);
; U7 q7 h& q1 b7 T1 }, c" C+ h; k5 t  14)    } 6 v/ J0 a% M) f1 Q* }
  15)   }
2 N' A" Z9 D0 O# d  16)  }   
# Q/ b  G  e4 o( N    what is the result?
  T! b2 o; M$ q: h+ U  A.compile error at line 6 7 K8 d. Q) a6 l% i$ D; m
  B.the program prints pairs of values for x and y that are 1 A4 I! V: ~7 @  S- B% d; k
    always the same on the same time # B' d3 a9 k) H) w2 c5 M' V' R3 u) w
) [+ b& r( _- L! T6 ^+ \$ ]
28.class A implements Runnable{ : V  h+ E& F2 P( V, Y* f6 H
  int i; ' y. G* ]4 \& q) {( O9 @1 G+ ^/ H+ J) {
  public void run(){
) h. Y& N* e/ r& e! p+ t( r2 C   try{ ' z* Y& z6 j0 m: n9 Z
       Thread.sleep(5000);
" c1 x+ D0 a" k: V        i=10;
" T/ X" @: y5 L3 V: U1 C- J0 [       }catch(InterruptException e){}
8 \4 O$ s' e1 ?5 ^       }
6 K5 b& K0 ^8 G7 f( x1 e# c       } - a" M! s! ~, W# k8 _  Z6 P
   public static void main(String[] args){ $ Z+ }, |( u* \& _  k* `! |# A: u
      try{
$ [' z# R0 \4 Z8 B         A a=new A(); & U# H! }' F6 B, S* d4 V; @
         Thread t=new Thread(a);
) G+ B1 ~$ G1 V& x  S/ M         t.start(); % X- i# |' E* c7 u7 \2 I" Z
  17) 5 o; U( K4 D# O
      int j=a.i;
* m* o2 B% c& O" a6 n  19) 0 V. p7 J7 x6 H( t6 l4 C: r
      }catch(Exception e){} - S8 h& }. ^& c' A0 c0 U  D7 c
      }
) @4 E6 t' w( \! p. l/ _      } / Y8 e0 X5 f: ^6 p
  what be added at line line 17, ensure j=10 at line 19?
! k9 r" S  n) y; U6 I  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   & j/ ?( A7 f* Q6 P# Y1 X0 i6 b
  E.t.notify();  F.  a.notify(); G.t.interrupt(); + h( U; W+ F2 d/ h8 B
29.1)public class X{ 4 g: ]5 N0 P8 d9 j. {
  2)    public static void main(String[] args){ 6 z& ?* X' t+ C
  3)     String foo="ABCDE"; . F& T/ b9 A: i& J/ g5 E
  4)     foo.substring(3); : N. t8 x9 t+ a9 `% }
  5)     foo.concat("XYZ"); 3 w3 X) I* X' V% q2 m, B6 \
  6)    }
9 l; j# L9 v7 k7 K0 k) H" o  7)   } 2 j  ~( o1 |: h7 s- l9 _3 Q
  what is the value of foo at line 6? . f3 a" V- h" n, x! c' A" l
30.  public class Test{ - |6 j; x+ t( P
   public static void main(String[] args){
% T+ b  n2 D1 _% @   StringBuffer a=new StringBuffer("A");
: e' z. Z- Q8 Y3 i  G  |   StringBuffer b=new StringBuffer("B"); . ~, S7 K: H& ]# u1 b7 i8 G) m
   operate(a,b); : m% L" x( e% o) C
   System.out.pintln(a+","+b);   p( c; j5 ~5 S- b. D: [; f6 v
    }
; V. o0 b8 G: H& t' r; {   public static void operate(StringBuffer x, StringBuffer y){ - [0 ~+ p' A1 N! x! ?8 V7 m3 f2 e% w
    x.append(y);
1 P1 @% `( A0 |6 A' d2 Z1 L- K  d    y=x; 3 Y9 Y9 Y2 b, ^8 B
   }
5 u- u: z6 L0 K; x$ P4 |) g: m2 t   }
. P9 P( |. Q) u7 Y8 C. E- C7 x   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享: i8 _+ p& ]& D" M" S6 ]  c4 Q
我已下载。。。。。* V. |  a6 ?9 X0 a* t
特感谢您的大公无私
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, 2025-11-18 03:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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