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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题
1 n9 @( H2 \& `( n4 {1.        给出以下程序:4 R, \1 B: ]2 x* M
1. public class Colors {" l6 }- B( }5 ~
2. public static void main(String args[]) {
0 m4 ~" J8 @! n, A! l0 k* T3 b3. int n = 1;" L" b/ D5 F! X4 K8 T
4. System.out.println("The Color is " + args[n]);; Q1 U: l' Q" U  o
5. }4 M; v0 U+ A$ d" ?: s- z
6. }
4 K# p9 b& w* m4 i5 {+ {假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
5 `7 V3 g# H% k+ K" F" |$ ?3 pA.        Colors red green blue yellow
$ L- H3 C/ j  ]8 I0 z4 o% L8 DB.        java Colors blue green red yellow
5 @% U5 u' |. rC.        java Colors green blue red yellow4 g- v+ N- X5 y5 `( r2 ?1 Z% z* G
D.        java Colors.class blue green red yellow
9 O3 a' I- k' K7 c, D3 XE.        java Colors.class green blue red yellow
* P9 d2 W  c4 {/ E; @) `2.        读程序:
7 k! n) r9 k% U+ i: ~1. public class Test{: _3 N& p& G0 p: m
2. public static void main(String args[]){) k8 z( U( D8 S4 h  w8 v/ z
3. char c = '\u0009';
8 n/ L( ]. T& E4. if( c == 0x0009L); t/ W5 t) i9 P' ^( g- f
5. System.out.println("Equal");  [' c; o1 F( X+ Z, {% T/ A
6. else System.out.println("Not Equal");1 I3 F+ S- m7 x
7. }
2 S5 o" b2 O3 Q5 {$ L' R9 V8 Z8. }
: V/ o# o5 M% B" ]; q( c& o当编译和运行该类时,将会发生什么:/ S8 _9 M8 A5 S8 @* z
A.        程序因为第4行将出现一个编译错误
9 |4 ]: r3 `) S( {  A5 `6 m# c/ ^B.        程序因为第4行将出现一个运行错误
: D& I8 {% `' t5 e2 vC.        程序因为第3行将出现一个编译错+ t- e$ ?0 i/ b; a4 W- X" i4 L& S
D.        程序输出”Equal"
1 x8 [$ j5 b5 g" q( eE.        程序输出"Not Equal”
* N0 X( c+ \3 T4 @! p. b3 Y. w3.        读程序:
1 B: w, e! j. W5 [1. public class StrEq{
% {$ M& |% a" B. _% B0 m2. private StrEq(){0 s: E: j" |& F
3. String s = "Bob";5 {! [9 L* u+ f$ X1 u" K
4. String s2 = new String("Bob");
2 p& V2 {3 U+ ^( n1 N: G5. if(s == s2){
! E# ~( K1 ?  D6. System.out.println("Equal");$ e9 E0 |) V! |3 X, M' w  K
7. }0 i+ h( o( U+ e6 N9 o$ M
8. else{3 @( \1 w3 g# W0 R' l4 T1 t
9. System.out.println("Not equal");) t4 x1 v, l5 A6 v# x6 C1 _
10. }7 }; R/ G$ b8 U; r7 [( q7 N/ }
11. }
  k. C  @5 m! Q- l+ U/ J' m12. public static void main(String args[]){
: {% A* ?% {0 G$ Y13. StrEq s = new StrEq();
5 h. f9 f5 ?& i( N14. }
" c9 j( t/ V8 G8 ^# \15. }
3 G7 h' g3 K, ^% M+ E. f% c" L当编译和运行该类时,将会发生什么:
% G$ m( ~" [  ?8 YA.        程序能够编译,并且输出“Equal”
, u( m0 J% G4 q+ ?+ B) Z# f1 qB.        程序能够编译,并且输出“Not equal”4 `' y0 W3 y/ S: y4 q
C.        程序因为第2行导致一个运行时错误5 Q* ~8 M' }7 G; ~- U, U$ U0 A) A
D.        程序因为第2行导致一个编译错误
/ D& E8 X* R: D( o& \4.        以下那个赋值是非法的:
& Q% p7 q1 K) _4 u4 Q% e' u/ E5 ?A.        long  test = 012;+ [8 L% p( E. d2 M' c1 `
B.        float  b = -412;
" e% g8 x+ E7 t' eC.        int other = (int )true;
1 F  D- \$ o$ Q5 {. @9 y1 @) lD.        double d = 0x12345678;
6 b- _1 T3 ~+ W% m# yE.        short   s = 10;
4 T+ W2 H0 L3 E% N2 B5.        读程序:/ V! T- j6 y4 I
1. class CompareString{0 v; c1 M9 c% R3 Y0 n
2. public static void main(String[] args) {
, F2 f1 e9 e; G5 ]  ?# q& o3. Integer x = new Integer(5);
1 I2 T  K4 I9 v0 C4. Integer y = new Integer(5);  h/ t1 m$ I7 N# ?# ]+ o
5. Integer z = x;* [( x$ P* o( l3 L' m4 F) g
6. if ( ______ )' j( {) k4 f6 d4 d/ i, h
7. System.out.println("true");
7 P- k* Q! g6 c( s: m8. }
' ^& X; I$ z8 i9. }5 O- G  d; C2 X2 f
以下哪个选项填入第6行后,不能输出true:
) {+ O$ s* B% E9 Y- EA.        x==z
  H9 H! \& \2 @$ t! K+ N8 RB.        x==y% v* ~( j- q' L2 m/ @6 T
C.        y.equals(z)
8 \$ @6 ~" u) N. ]0 W/ z0 V- jD.        x.equals(y)/ x2 U. p4 S2 T; N- l  g5 y% y
6.        读程序(双选):5 t3 M' v5 m, O) i
1. public class Declare {. t1 I! E, i# N
2.0 ?5 g9 m! j( F6 A. |2 N
3. public static void main(String [] args) {
( c9 C8 f# Y2 ], G. ]& ~4.8 o7 b- R! q. j9 F- X  g7 R, Y
5. System.out.println("The variable is " + x);
  Z6 `1 i5 h% P3 T" `6. }2 k" j) e) H6 }2 d6 l
7. }
4 m: ~3 Q. \8 Z7 O+ T以下哪个选项中的代码可以使程序编译通过$ ?9 G! u2 {( t
A.        把“int x;”放在程序的第2行
0 u8 o4 D! s; [5 ~B.        把“int x;”放在程序的第4行" p$ X+ t8 d9 L/ G7 g" m. @
C.        把“int x=5;”放在程序的第2行
5 U2 N$ K, [1 D1 o6 F' D6 uD.        把“int x=5;”放在程序的第4行" [0 r8 c7 ]* m: Q0 O3 j( a9 B6 p
E.        把“static int x;”放在程序的第2行7 D4 d" {; Z2 \- H* N" S% y
! m! D& o1 a& |( z1 }* Y( D3 q4 a
9 H9 T8 |# f; C- V3 q. Y
3 k6 W7 z+ p8 q) ~% c0 v* N
7.        读程序(双选):
# P2 c" z1 a* v! J( g9 B1. public class Child extends Parent{  S" `7 X+ c: E# Z3 s. r+ s
2. int a, b, c;7 }& b3 V( }# c6 \% _
3. public Child(int x, int y) {
+ _6 e3 Q! l0 Z  f) X* ?4. a = x; b = y;* q5 P/ D; O& A0 R
5. }
( D- d8 ~. n. {1 w( J6. public Child(int x) {
& B: \& K  ?; R5 n. l0 M7. super(x);) `/ }7 v6 j9 q' E' L  R5 M
8. }  \4 _$ c8 l$ s8 `
9. }0 T. Z$ }5 N/ q& {% W  A; X3 }$ w
为了能使该类编译通过,下面那个构建器必须出现在父类中:
0 \. [5 a  j8 P/ z. z+ d9 _A. public Parent(int m,int n)6 ?9 o; F- ^9 s0 G
B.public Parent(int m)
, X; e. _6 d3 J8 y' N5 H+ r# @C.public Parent()  g1 v( j0 P. o$ \
D. public Parent(int m,int n, int o)! @9 t$ o& m  v# N
8.        读程序:
( g4 v2 J5 d  L1. public class Derive extends Base{
; q) K; |+ `) T3 T7 K/ [2. public static void main(String argv[]){! O* m: A" p3 Y
3. Derive a = new Derive();
+ Q' d+ |  V, g9 c* y& k4. a.method2();
8 E, }$ i: M3 j* m# Y  R5. }
/ P' K, y. x: Z2 B6 }6. public void method1(){
7 ~' _  ^5 S1 N7. System.out.println("method 1");
: K) g! S4 C6 G! C5 }" i8. } / P; J# u2 m9 @0 f: F( D/ O
9. public void method2(){- g8 ]  X- U$ T
10. method1(); - n2 B" c; G: w; b) J2 g$ p1 ?
11. }
. o# G1 B9 Y8 }5 C* |- [9 I12. }
! J' h2 G  k) g$ i% c  [13. abstract class Base{
4 k, l/ Z/ A( ^9 a14. abstract public void method1();
8 |- Z5 w" y, S15. public void method3(){9 h1 l% T  K2 v" I( `
16. System.out.println("method 3");9 v' n. l# w" }3 }/ n
17. }1 U; O: ?$ |0 @
}$ u8 p8 F$ A% r$ [" ?3 a7 J
当编译和运行该类时,将出现什么:+ C' D; C3 H/ R# F( ~8 ~
A.        程序输出“method 1”
* t8 N, o6 m8 b. a6 ?$ R! mB.        程序输出“method 3”
$ u5 G  A8 T8 b9 o% z" XC.        程序因为第15行而出现编译错误5 _2 O1 D! J8 a5 P/ N* f
D.        程序因为第15行而出现运行错误
: B4 H" V" M$ @" y6 g! J6 W9.        以下哪个接口的定义是合法的:4 @' y& i- m3 y  K  A' L
A.        public interface A {int a();}" m2 x# X7 l6 \6 H5 m  y
B.        public interface B implements A {}
: z( a3 V) P! j/ }. a& w! J) [" IC.        interface C {int a;}) ^8 ~- k+ u4 C  v' N/ B
D.        private interface D {}
' _( z8 }) o9 ^( p10.        读程序:7 x$ F3 k. y% |. Z2 @$ C4 L8 T
1. //File SuperClass.java4 J4 _# z0 w7 R
2. package MyPackage;
9 r0 D) ~, _9 X' G3. class SuperClass{0 Z( E5 T$ E4 L% c9 ?' [
4. void myMethod(){  k" e0 G8 `" a- V/ _8 J
5. System.out.println("SuperClass");
( k4 ^$ v! V+ E4 C( W; K  l5 }6. }
4 g7 X9 d8 {* H# Z: A1 s- X7. }
. F# \& S% j4 f" k3 X5 Y8. //File SubClass.java
3 p$ U& [  g* R& W9. public class SubClass extends SuperClass{- q8 I5 \4 y' Q) A
10. public static void main(String[] args) {# F: H/ X/ @, y. k: u) W
11. myMethod();: k' \/ l! G4 _- }( L
12. }
. Z& D- t& j7 _+ G" y1 C  x8 e% _13. }
9 c$ l: i' {9 w9 u3 G+ @$ G, n当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:& J0 D8 d/ C4 q, g" n; }( |
A.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
5 W- J2 p& G$ PB.        两个类都回出现编译时错误) c% d' @4 D; h8 h0 V
C.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误
) r1 y' Z* m  L3 t- K  S  o  sD.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误! U; b8 K$ Y  v1 v8 U
11.        读程序:
4 D8 K7 T+ H* I8 B1. public class Test{
. i3 [; E/ u3 L* H5 Q% {5 a2. public static void main(String args[]){
) c" p) O! h8 Z+ W3. int[] i = new int[5];- _% f3 x2 {3 U* R
4. System.out.println(i[5]);
, r) \- c% ?1 ]6 d5 A% w5. }- H: m' R' L" e1 N, g* T( d5 _1 c
6. }6 c( h5 E( g0 E: e
当编译和运行该类时,会:
9 P- a% u' {+ }# DA.        出现编译时错误
' v& w; [9 V$ S  {! xB.        出现运行时错误
9 ?% o1 X% J, V( C, sC.        输出06 F; G" H# [6 q  i5 W
D.        输出null, k, m3 I' t$ X  Z/ c8 N
12.        以下哪个选项是正确的数组声明或初始化:
, q4 j( N0 e6 {1 D+ v' hA.        Array sizes = new Array(4);" O9 [+ W: V% s( }8 _
B.        double [] sizes = {1, 2, 3, 4};
( t" K3 \2 {4 l* w( [0 @C.        int [4] sizes;
+ U9 y( |: z% z9 o! |; J- ND.        long sizes [] = new [4] long;
* ~! G$ O/ M$ i0 q4 O& r13.        读程序:0 U, Q7 J* z9 l5 e& {0 A* I1 `2 p
1. public class Initialize{
; ^, w% K0 O. n4 X& w! K2. int x = 200;
3 Y" I$ r8 [6 X% \' A3. static {
( F  I% o& z* F- {6 x" g4. int x = 100;- o" r1 u9 `+ S. D
5. }) b& E& w. U- [: z8 A( E$ \
6. public static void main(String[] args){
+ w+ }1 U8 B& s4 a9 `0 Q7. Initialize init = new Initialize();
* w6 b3 t# d  o5 E" n8. System.out.println(init.x);8 Q6 q6 _- o2 W" F. l9 {
9. }
& [! w( @: a2 v* n10. }
' @  S3 }, L# [0 ^5 W; r1 o; u当编译和运行该类时:
" v# R$ n: r# m! gA.        程序因为第3行产生一个编译错误
9 o& G* ?* v+ ^; |; A# m0 p) {9 rB.        程序因为第4行产生一个运行时错误
# Y, V+ h' e; ]3 TC.        程序输出1009 e  {; I4 Z; }9 `
D.        程序输出2000 Q3 o/ X8 {, S% s9 X
14.        读程序:2 ~" E) C! u* P( r9 A, X
1. public int abcd( char x) {
$ n4 {# }) }: |9 T2. if ( x <= 'M' ) {0 L  W+ Z9 r# W, U0 d
3. if ( x == 'D')
* e/ _* u' ?, {4 ?8 n* b4. return 2;) O  J/ {. ]! p$ t
5. return 1;3 c* R1 f6 G3 k  F4 `  j2 f
6. }) Z( T% G" [' F2 s- U! E2 i+ U
7. else if( x == 'S') return 3;
" Q6 \: {2 q8 h6 z8. else if( x == 'U') return 4;
- w/ B$ {. ^: W1 j; B9. return 0;+ w$ H" ?1 o& E3 b2 k
10. }
. R' t0 ~2 f7 R( d3 K: z1 G在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
. X3 j% x3 x9 B! o  F0 T3 NA.‘X’  |; x; ?% l3 j
B. ‘A’
5 T2 U# c  \$ IC.‘D’/ M, Z" c- t. [$ g6 s8 p
D.‘Z’' d* T# j, {& D3 x6 `
15.        读程序:
+ F6 H; `- Z/ F1. class TryTest {
: N3 O9 |3 V& Z5 P8 b. h6 c5 J2. public static void main(String[] args) {" y7 R" y0 t7 b  ^. D/ Q" b, v
3. try{
. w8 t2 l# y3 E1 n. O$ q0 a% F) v4. System.exit(0);
# I! V) J* o- v  C5. }+ C; T; w/ D! x8 G8 Z
6. finally {
9 p; [  b) ~- F/ _7. System.out.println("Finally");7 d: a( X$ D! p  ?8 ?
8. }9 S" R! N8 k7 K/ q
9. }- U7 J; B; S# G5 W. C
10. }
; k: D& ]3 j7 @) {1 S* h当编译和运行该类时,将:
# `/ x. I$ @. K8 x4 O2 z9 MA.程序因为第4行出现编译错误5 t% }6 w- k9 [. D, Q
B.程序因为第4行出现运行时错误
; X. m( d6 ?' _7 ~C.程序因为第6行出现编译错误- Z* J$ ~" ]+ d$ W* ^
D.程序因为第6行出现运行时错误
7 \) j' }) C( }: IE.程序输出“Finally”: i' C. z1 G8 b# r# b5 v8 h* c
F.程序可以运行,但什么也不打印9 g, a. L  a7 m7 E" @% w# j

7 z2 K4 E/ y% E( c* y16.        Given the following variable declarations:
) V* F2 F1 \3 B6 JBoolean b1 = new Boolean(true);( `2 w# w1 ?  d
Boolean b2 = new Boolean(true);8 L8 z. y1 M6 M3 g  D
Which expression is a legal Java expression that returns true?
) c: o/ x/ A0 {7 iA.        b1==b28 w/ n  M  m# I- C1 V3 B
B.        b1.equals(b2); ?5 v, ~1 {& }- }
C.        b1&&b2# F6 L% g1 l3 @! [3 T3 C3 s& n0 _; _
D.        b1||b22 i  y  T+ L/ J3 X0 R
E.        b1&b2
4 G9 ~( @8 b* n% Z! ^% ?: LF.        b1|b2: ~# d# Q! ^4 l) T! V
17.        Given: " I% k+ e% g/ u8 Z9 |; Q
1. public class Employee {- b! l5 q3 f6 _3 `: T+ V" v
2. 1 @' K. S. h8 D5 n6 }# p! ]6 n
3. }
; z( b2 A  e' s) v0 B4. 6 n) x+ b1 ]; n6 A1 X# o, S3 @. g
5. class Manager  extends Employee{
1 B+ K% M, c9 q8 A$ D( y6. }$ }  s' o( T  C- s; m* q
What is the relationship between Employee and the Manager?" C, F7 g" `& X# w
A.        has a
- x% H$ q; x7 V9 r  D& C2 n4 r, BB.        is a& K" f+ ^6 X' B2 C$ T! _5 ?/ R( d
C.        both has a and is a
- N% P9 f0 d* T8 g; fD.        neither has a nor is a5 _, M# W3 }% q
18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
  _8 i/ k6 P( r8 i& HA.        BorderLayout
0 f* M: Q9 F5 C8 ~* CB.        FlowLayout
; \: i# F$ c! k3 zC.        CardLayout; \' C4 Q7 E: r' x' L: A
D.        GridLayout
: A; r5 V( }6 y& T7 n- G; d" C19.        Which of the following AWT components can generate an ActionEvent?
4 s2 ^/ e1 b2 S2 |$ q0 \A.        java.awt.Button
9 L% ~0 T9 u* G' F; t/ AB.        java.awt.Panel4 b/ o9 {0 {! _/ t% I
C.        java.awt.Canvas
  A. {8 n: e6 v! k, f2 M' v3 nD.        java.awt.Scrollbar5 I( J( x6 ]) h% f+ [. b7 E* f
20.        What kind of Stream is the System.out object?
2 B- k$ n2 v+ A( Y8 r$ `3 UA.        java.io.PrintStream7 {) s  Z* A- g2 M# i+ N
B.        java.io.TerminalStream
# o6 T4 e* B) I. \" h- B& q1 pC.        java.io.FileWriter
- q, _0 ~1 g1 A& F% `& Y  ]6 KD.        java.io.FileWriter: P/ I+ _, W. P  ]) g
21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)
1 h+ `% r8 X! K3 W: C2 ^A.        java.awt.event.FocusEvent
, z  Y* J* e3 B" iB.        java.awt.event.KeyEvent
; @1 i8 K% u& B( WC.        java.awt.event.ItemEvent
, v8 w4 ]' k; w3 H2 PD.        java.awt.event.ActionEvent
5 J/ A- Y2 p: P& C. _22.        Which of the following methods are static methods of the Thread class?(双选)
. V' J# p+ K8 w2 V$ ^A.        sleep(ling time)
$ p; h. i0 Z' J9 [, A: b7 ^B.        yield()
6 B# h! H! B: e0 i, ^+ ]% BC.        wait()
) w5 `- o& G9 CD.        notify()! ?0 F; Z# C! h. @, `* o/ |% U& b
23.        Which method do you have to define if you implement the Runnable interface?
  Y3 X6 i& `- W& CA.        run()
; ^2 N3 V* V" F6 b+ Z7 v/ oB.        runnable()! q; A6 b2 a% q7 g; S
C.        start()
+ f$ V* r  t  x4 s! `! d! hD.        init()
2 o9 _( D5 [! ?( d( JE.        main()# J7 p' c% I% O9 H0 X
24.        Given:
# z# M4 d$ M* |( J- q3 C' K1. class MyThread extends Thread {. S0 o) H5 r2 x$ p4 `3 J
2.
6 D6 V) d/ V! C. U+ h/ I3. public static void main(String [] args) {! B4 D0 }, ^3 L1 h* p
4. MyThread t = new MyThread();- D: s) x+ {- m6 a& W
5. t.run();
8 R; C* u% N# }/ ?5 s3 k8 E% T5 n6. }  r, H' A0 J3 K" n. |3 V! ]
7.
! h% [  P# o  G8. public void run() {
: r: T+ @, V' I. y7 k& c) M9. for(int i=1 ; i<3 ; ++i) {
3 O% f! ]1 w; F3 k. c- c10. System.out.print(i + "..");" e, F# k& |9 ]0 {  }
11. }, r" ^+ t* z- t. ?( F% t1 B  z
12. }
" j4 w+ Z! Z4 W13. }" P7 f0 z# d* I; @/ o' ?/ ^! E5 Z
What is the result of this code?C4 p2 C6 M4 {" i+ q
A.        This code will not compile due to line 4
# j" l6 @; H$ Z* H+ `: h) dB.        This code will not compile due to line 5
) F% q7 E4 ?1 ~; c, n  W$ c' xC.        1..2..& s% l; ~! e' I5 q3 Q5 k
D.        1..2..3..
2 b0 n- x9 S) d# ^! J$ m25.        Given a local inner class defined inside a method code block, which of the following statements is correct?1 H' c& w* _0 }, E; N6 P. G, B: c
A.        Any variables declared locally within the method can be accessed by the inner class
6 H- S7 B' s* fB.        Only static variables in the enclosing class can be accessed by the inner class& ?# w" p- {! r
C.        Only local variables declared final can be accessed by the inner class
* }2 `0 \9 @' U8 ED.        Only static variables declared locally can be accessed by the inner class.
' V& `4 T9 x9 [% i1 |9 k' {
8 o8 w, R9 H5 f7 m& u+ i
: P/ _) U; l! U" {$ h1 l8 \8 m( x' v, d; A
26.public class SychTest{   b4 }8 Y% ]/ x* v4 F- C4 `/ ^
   private int x;
2 `  g5 f+ ]3 N- q7 E2 y( g   private int y;
  S8 u) d* _# g) N/ [   public void setX(int i){ x=i;}
  `8 w( p) M& d   public void setY(int i){y=i;}
# L$ ~( O% p5 z( Q! G7 D7 i   public Synchronized void setXY(int i){ 2 S6 x* l/ x9 s0 n
     setX(i);
! C; \2 y. W3 \8 P- s! d     setY(i);
% _6 l6 l- a1 W* r* X   } 5 X$ T/ z8 u, `/ i: [7 C1 R0 I9 |
   public Synchronized boolean check(){
3 Y6 G3 K9 l0 n. q        return x!=y;   3 e- ?6 g# f* `# g$ [4 G
   }
, @  u# t1 Z9 E( Q6 Z- f8 ~   }
6 @) y$ O. _/ j    Under which conditions will  check() return true when called from a different class?
5 E+ f( h$ b& w   A.check() can never return true. 4 ^0 |& K4 s' J
   B.check() can return true when setXY is callled by multiple threads. : U- r3 Q, q0 U' j( u/ q& o
   C.check() can return true when multiple threads call setX and setY separately.
3 B/ w+ i" C3 E   D.check() can only return true if SychTest is changed allow x and y to be set separately.
- t3 k" c' X9 g' G3 w3 M8 l$ C, G* H* K- ^2 W
27. 1)public class X implements Runnable{
# B% H/ E4 Z+ |  2)private int x;
5 ?( A. Y& F" I: x, _) J6 ?  3)private int y;
! _# S3 S: P4 P  4)public static void main(String[] args){ : m3 U% Z/ e* w. L$ ^
  5)   X that =new X();
" j, U4 e1 c* W  6) (new Thread(that)).start();
) q. v; w0 d, C. F3 a' D9 }! G  7) (new Thread(that)).start();
' _7 W9 m* K0 ?5 b- C9 c   } + c. ^9 _) ?: n
  9) public synchronized void run(){
+ _* s% T6 N3 b, L  10)  for(;;){
) T( ?1 a$ I1 u( O8 k  11)      x++; + y7 [; w) V" G# m, s' @, I
  12)      Y++; 1 B- u* D: n# n: c8 c" w
  13) System.out.println("x="+x+",y="+y);
  @( S( Y/ n/ C9 e  14)    } ( O# M5 ^  y- F- D/ j$ n# {! _% H5 C
  15)   }
1 V4 Y/ W$ K7 j2 N  16)  }   
$ D5 n* J# O( K; h- F    what is the result?
- j/ @% U! ^! P. H4 T, e  A.compile error at line 6
! B, Y' j* o, a! S  B.the program prints pairs of values for x and y that are
: l6 D7 t  Y3 {' _' N  E6 F* n    always the same on the same time , _/ {* X3 s" X2 I, D
$ m. r8 b+ G. e5 [7 Y
28.class A implements Runnable{ % G! q2 n' @! Z. `4 _( V
  int i; ( k+ K, U3 h' s+ O
  public void run(){ ( ~& n1 k5 ?' k, r
   try{ 0 e: O/ n0 e$ J
       Thread.sleep(5000); , B1 ?( K9 ?1 c
        i=10; . H7 s7 t2 q$ Y- }0 N; N5 C
       }catch(InterruptException e){} ! L& A$ ]. k3 x, H1 s% r& s
       }
. o3 D( X* P9 E% [1 n       }
! f4 `, y! ]* S: T4 F" b/ w) {   public static void main(String[] args){ : A0 ^! n5 N3 ~' m
      try{ ( q! ^" _: @6 e; I8 C
         A a=new A();
4 s9 i# J% i3 U9 E, \         Thread t=new Thread(a); 5 I2 K8 h, w9 y+ y3 o
         t.start(); ' e' p3 v9 Q/ U8 A3 G" P) e8 O, ~+ O
  17)
/ |! W( i- p$ M# L      int j=a.i;
8 I1 ]4 C/ K5 \. R  19)
7 v# Z! M. {1 h% s      }catch(Exception e){} & ?! B5 E* m4 ?$ U2 ~" O
      } : L. }! ?& [' m2 [# Q
      } 9 K# l' H2 Z: K
  what be added at line line 17, ensure j=10 at line 19? : H4 R) x8 j5 m8 E; C6 X/ c
  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   ) O, o$ P( f5 u% D; i- H0 ^
  E.t.notify();  F.  a.notify(); G.t.interrupt(); * n9 Z# y, c0 h& D$ X# h* ^7 X+ w
29.1)public class X{ 4 U7 P! P0 m/ o
  2)    public static void main(String[] args){ ) f; k1 e) j1 L1 d2 C* D+ _4 J
  3)     String foo="ABCDE";
* X4 ?5 H. Z4 p( u  4)     foo.substring(3); ! X7 J- M) e& V! K8 G  }' B
  5)     foo.concat("XYZ");
: w0 p, E4 n2 i7 H" R5 Q  g  6)    } ) n" U& W# \* L7 r% Y& k) E
  7)   }
9 L0 D2 ^# w0 S' b' ^  what is the value of foo at line 6?
2 D$ `' R- T+ d# E) W6 w+ B! Z30.  public class Test{ , G# f" ^2 P! v7 o0 I& m5 V
   public static void main(String[] args){ # r! M8 f4 j' w
   StringBuffer a=new StringBuffer("A"); 9 F, g& ^% ^  a$ I5 _* U
   StringBuffer b=new StringBuffer("B"); 2 S5 d" |0 G$ l' |' E/ b
   operate(a,b); 7 H; n5 @1 q8 h
   System.out.pintln(a+","+b); % ~4 i" z: X+ V: f
    }
6 q( x. f" g, m! V2 p: Y   public static void operate(StringBuffer x, StringBuffer y){ % T; J7 A+ ^( j* I6 e+ _
    x.append(y);
: i; ?2 y4 |' N9 _, j    y=x; & `, Q' `8 I) O/ n6 a
   } 2 l! H! ~" H, E2 B9 x
   }
& U- Y( @, O! ?1 m) |# g   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享
7 C+ b: d& x. f2 r7 [4 O我已下载。。。。。
+ o: a: y$ E- T3 e特感谢您的大公无私
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-2-25 00:35

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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