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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题/ b9 m8 m7 w4 {. D' w- c( A
1.        给出以下程序:1 A8 j2 `  g3 }3 m
1. public class Colors {% u, s, x7 H7 _3 j! O+ t+ C* F
2. public static void main(String args[]) {/ @+ d. R# Q6 B
3. int n = 1;
+ W& v9 f# s5 i4. System.out.println("The Color is " + args[n]);( {* Z% h7 v3 v" Y
5. }
  A2 n5 \2 R5 [1 c8 ^! _6. }3 N8 C6 v) F: }1 A" R
假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”" L$ o5 Z* s& B2 `; c: E
A.        Colors red green blue yellow
! H3 ^* W1 b; c# [; }/ x" EB.        java Colors blue green red yellow
4 a1 \0 v; n  @) S1 K3 O$ gC.        java Colors green blue red yellow9 V& p4 p7 p7 O' n% d! F5 p8 y' @
D.        java Colors.class blue green red yellow6 @* U& p4 f% F. v5 s; \. U6 b9 q
E.        java Colors.class green blue red yellow" D" r4 j( e. u& C7 {+ a1 |
2.        读程序:
# a, \6 b& z9 d1. public class Test{
' M% ^5 ]& }  k0 m" P. K2. public static void main(String args[]){
- B3 I" p- F/ H# Z7 N: W3. char c = '\u0009';. N7 ~9 h8 i: J- k
4. if( c == 0x0009L). B& f% n  Z, U& `3 h6 V6 D
5. System.out.println("Equal");
; C, ]/ D7 M  J6 T+ F. [7 b6. else System.out.println("Not Equal");
- b+ B( n% R# [7. }. h* h8 H0 v! h8 s0 {0 ]
8. }6 N: ^# o1 S& p9 ^0 j+ Y) D6 Q
当编译和运行该类时,将会发生什么:
! l3 Q. b9 B* l" d* ZA.        程序因为第4行将出现一个编译错误
) Z5 m0 H4 D7 @8 g; N* W0 j4 [B.        程序因为第4行将出现一个运行错误
- n6 n& Y3 ^$ MC.        程序因为第3行将出现一个编译错" b0 V5 A7 u3 P$ w
D.        程序输出”Equal"
9 K( R& e$ K) k5 F- LE.        程序输出"Not Equal”
. c4 t% k0 g% ~3.        读程序:
6 a2 F" E: |7 O. h1. public class StrEq{
+ }  ^' R6 G1 j$ ~$ V# x( K& p2. private StrEq(){
' t; p! Z1 U/ m1 `& y: e% t3 ~3. String s = "Bob";/ w5 T! Z1 h: |/ w0 A
4. String s2 = new String("Bob");
1 c1 m+ q1 C, G5. if(s == s2){0 v1 M5 D4 g! r% D  u
6. System.out.println("Equal");% L0 \6 p3 h+ ^& w  f0 w3 `
7. }
5 o) Y" I( u: ?( F: X8 Z9 g6 p8. else{
* |8 s, `) T$ P) r1 g( M$ Y7 d9. System.out.println("Not equal");7 e1 o; r  L, L( o( [' R
10. }6 i+ C! i7 i1 ?6 V: Z" C# s, E8 X
11. }5 f# c- J, N% g* p. \
12. public static void main(String args[]){9 d; [1 K7 W- @( S+ a
13. StrEq s = new StrEq();
+ [- Q4 }6 ~5 {" w- Q6 K& g& m14. }* D5 \, p. O( i0 n5 @
15. }
0 z- |! g8 s8 A7 P' A# Y5 U当编译和运行该类时,将会发生什么:, }8 q* k' m6 ~5 S) o
A.        程序能够编译,并且输出“Equal”
" `7 F. B4 l! o& I% ~: m& E& ]) I* d: iB.        程序能够编译,并且输出“Not equal”
; t' w% m  F, [4 \: hC.        程序因为第2行导致一个运行时错误
  u( L2 J  F9 z+ FD.        程序因为第2行导致一个编译错误& O% r" M4 b7 z1 J+ v  ]' E
4.        以下那个赋值是非法的:
0 f/ V3 q$ \' q4 v# sA.        long  test = 012;
: w; F" ^. t  L( S9 S% CB.        float  b = -412;
7 e) n# `# ~3 KC.        int other = (int )true;0 ?; X% q1 S3 E- R
D.        double d = 0x12345678;. l! {7 C  Q; r* E
E.        short   s = 10;
/ B) o/ L' f0 [3 x5.        读程序:  X3 F5 s" H' L1 v  T
1. class CompareString{
. M* q0 I4 F6 {% ~* K5 Y2. public static void main(String[] args) {
" i. h& M6 X( J/ L. }! U3. Integer x = new Integer(5);
$ Z. l0 s1 a1 M) u5 V/ j4. Integer y = new Integer(5);, _0 \+ r% j  i7 O: ~8 _* i/ }3 L
5. Integer z = x;/ y, n; f, y. S+ G5 a- R) o" w
6. if ( ______ )
; u* Z) z+ P& E7. System.out.println("true");
% ~# `+ i8 s' ]' q! S. g8. }' N- `: U  t$ r& D% L7 B
9. }! ^! W- k7 y# j& Q
以下哪个选项填入第6行后,不能输出true:
- N# F0 g" r: |0 @A.        x==z( q' _, ~' _) m6 u; N8 M# l
B.        x==y: m$ u" X4 b$ `! k2 r% ]5 D6 N9 n7 a
C.        y.equals(z)9 ]/ ?, _4 |8 [/ S
D.        x.equals(y)
, T9 m. A2 s* [/ f* l- p( i( l' ]6.        读程序(双选):
- N" g" e. Y7 S  t1 K- @4 ?- G4 A1. public class Declare {/ K. j' b& {8 b+ h% V6 n6 F; V0 r
2.; K+ Z8 Q5 P; e# X3 j
3. public static void main(String [] args) {  J  g' M  I& n
4.
8 ^: a& x' \7 `0 y+ _5. System.out.println("The variable is " + x);
3 L+ g9 c1 Q. V. `1 @7 b6 W* Y# z6. }, D8 _, v4 U4 ^2 G
7. }, X. _- z3 l+ ^: Y9 E2 G
以下哪个选项中的代码可以使程序编译通过& m3 b& D/ k8 B; ~/ e
A.        把“int x;”放在程序的第2行
2 j2 r* J4 p8 D( L- r) o$ YB.        把“int x;”放在程序的第4行* g( T! p. b/ _" I- n
C.        把“int x=5;”放在程序的第2行
# N4 {7 v: T2 l8 H% [/ I7 E- PD.        把“int x=5;”放在程序的第4行) Y2 Z2 X& }% f* l( ^$ S: r) z
E.        把“static int x;”放在程序的第2行
  \5 ~% {9 F6 A% N7 E0 r! J2 a! C

+ C) x) Z) M( K
, [+ P3 s! Q; r' k3 a7.        读程序(双选):2 {6 U# W9 d7 ^0 V
1. public class Child extends Parent{
0 n7 K# q+ B0 ^7 p2. int a, b, c;! F; J* n4 Z# E& E# V
3. public Child(int x, int y) {
; G% N: o. P; z/ q4. a = x; b = y;
& y9 @/ ^- Q, J5. }
' Y% y$ `4 b0 G1 `  l4 z6. public Child(int x) {( G( N8 e- f" m+ w
7. super(x);
3 n5 A' E! d8 _6 b; b" h8. }/ Y/ k) M( i& Y8 ]5 m
9. }3 y. H1 U( _0 N- p% ?
为了能使该类编译通过,下面那个构建器必须出现在父类中:
% U/ D* B* T3 D/ p5 X% \A. public Parent(int m,int n), @5 P# `  D4 |% Q: F! `
B.public Parent(int m)' s( z; {8 T) o) u/ [* S' ~, x
C.public Parent()# q$ S0 x* m% U' p1 b
D. public Parent(int m,int n, int o)
7 a4 j" W5 A6 B* g0 h8 m/ B: k8.        读程序:
' G& f5 K4 b: f1. public class Derive extends Base{
& I' ], U' Z+ U6 i: ~2 z5 R( u2. public static void main(String argv[]){; C- l& g5 U+ H; U1 U  y7 R
3. Derive a = new Derive();5 R+ c3 l% y# A1 M% P% |2 \& ?
4. a.method2();2 [: H+ E% r/ w" }, g5 T  x
5. }" H& S4 D- x- J' g
6. public void method1(){5 e1 E4 y, k+ K: x! ^
7. System.out.println("method 1");$ g4 s% `9 `& o2 }4 c
8. }
6 b8 w1 ]8 z8 Z! |3 V+ ^! B- D9. public void method2(){
" V9 r" ^6 A9 \/ |6 m: z8 [10. method1(); 9 N4 K6 E6 l1 V( m" p
11. }% x4 G) h4 r2 y. E2 C1 _6 }
12. }
* s3 A4 a" z( n& v- `+ U! d  _9 N13. abstract class Base{
. j) p" J0 p0 ~5 A14. abstract public void method1();
- L: _7 i2 c0 Z15. public void method3(){, K9 K; ^$ C  Q
16. System.out.println("method 3");
# v) k$ N# j# s5 F17. }
+ S; t4 p- F/ w5 _* D1 _- }}9 B; G* I& ?0 Q1 L) F
当编译和运行该类时,将出现什么:7 H) _( @7 W# ~" I/ U$ ?
A.        程序输出“method 1”' W6 G$ p: V" L9 o% I& e
B.        程序输出“method 3”
4 b+ E1 N) S+ F5 tC.        程序因为第15行而出现编译错误
4 q1 |4 ?( c7 G6 `7 u8 B9 BD.        程序因为第15行而出现运行错误
/ e' q& y' d! i. `$ n- L$ R4 J3 `9.        以下哪个接口的定义是合法的:
8 I5 Q  ^9 D) H! M6 sA.        public interface A {int a();}( T! p9 L7 G0 L0 F5 ]
B.        public interface B implements A {}( _4 K4 f, J& D) b% Q. O$ F! D
C.        interface C {int a;}
. q0 Y/ Z5 v9 A" R  ^D.        private interface D {}2 N' Y) P4 |$ r: @
10.        读程序:( a0 C% E! _/ n0 Y, E7 ?
1. //File SuperClass.java" B5 b; h* H( F6 {1 E
2. package MyPackage;
0 w; K$ O9 Y# r1 b3. class SuperClass{
, ~6 ?& U# t$ w4. void myMethod(){
# K  k8 H  l) q' Y, e5. System.out.println("SuperClass");! e' x# l: w# B- f6 \7 E
6. }4 h) b0 h" d# y* \/ k9 R8 b& B
7. }# V8 A# o, G/ `8 F1 `4 i" @
8. //File SubClass.java
( @& a0 O; U  C% g7 B9. public class SubClass extends SuperClass{" d! m# C5 M0 |! F% V& p1 x- \! K
10. public static void main(String[] args) {- ~4 w( j. e9 f$ Y
11. myMethod();
3 |. C# M% ~' ]/ S4 F6 b# b( [& G& V12. }
( M2 E  i$ `$ {6 p3 @13. }
) j' S. M$ S& o当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
0 l! k1 S% U  w) ?( _& V6 lA.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”8 {5 h; R! P- H( k* n, R
B.        两个类都回出现编译时错误
- ?) B9 ~) M( S0 H. _3 mC.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误! W2 M  M6 b. b8 |7 m
D.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误
9 k8 b6 |: j! G* V11.        读程序:7 h3 u/ E8 Y  V& r# Y, _
1. public class Test{7 E5 Y% c( ^% U% n  k6 P
2. public static void main(String args[]){8 J7 T8 m1 g7 T2 a
3. int[] i = new int[5];
( |6 y4 l5 B5 T, ?$ E: u  f/ U4. System.out.println(i[5]);# @. I* C8 M5 ^' N) m
5. }/ G: u4 {: T* z9 r+ \
6. }
- o, o9 X# G! @* o% R& R当编译和运行该类时,会:
- n9 o, E$ ^2 [8 p! B7 v* E0 lA.        出现编译时错误
7 p! r) w. C4 b3 a1 E' }0 n( F% tB.        出现运行时错误6 [; e6 Y( T3 V1 O1 ?0 g, Y
C.        输出00 {" e) x: U/ L' F4 k$ N  j! `/ x
D.        输出null7 }+ K1 E3 m' I( e
12.        以下哪个选项是正确的数组声明或初始化:
9 i6 h5 D" o, d0 S+ YA.        Array sizes = new Array(4);
$ z" v' a% X9 \$ o+ Q$ D2 N9 {. P9 t9 qB.        double [] sizes = {1, 2, 3, 4};
9 K, `, Z* K! o+ p3 b! z+ hC.        int [4] sizes;
8 t9 i" |+ Y1 S9 i+ cD.        long sizes [] = new [4] long;
+ }( g6 B) `$ b+ K  j6 Z8 l13.        读程序:
: X+ ~0 X& N& D; O: _1 G1. public class Initialize{! Q6 [1 g7 X( ]* J2 C
2. int x = 200;
4 `$ d0 y7 ?# U8 f2 l# V- B3. static {
, k3 |$ W+ e8 o( _, l1 s4. int x = 100;( K( Z) E5 t5 V% Z
5. }
% |, B' r3 ~1 C- r6. public static void main(String[] args){9 e  _6 T, n( j0 Y; d  R: r
7. Initialize init = new Initialize();: R3 c4 |5 H, |7 x
8. System.out.println(init.x);
$ `- A4 A0 n, S8 @/ n0 ~) g5 L/ ^9. }
, W; @: {! D9 o) ~, O10. }% ~. G6 k- I# k& V" V
当编译和运行该类时:
3 |1 J: h0 r; F: yA.        程序因为第3行产生一个编译错误
2 r# M( h$ A1 e5 G7 _; D0 ZB.        程序因为第4行产生一个运行时错误
$ T( \# Y9 T" P9 ?) Z- mC.        程序输出1008 v6 c! Y; o0 g
D.        程序输出200
' E8 Q3 A% a) w14.        读程序:
5 }0 M* r- ?6 w" d3 E1. public int abcd( char x) {
' g; L8 _+ R5 _# x2. if ( x <= 'M' ) {
/ }5 y( k# m( j7 o3. if ( x == 'D') ! [8 G6 Z7 Y* P4 `3 Y8 p& \
4. return 2;
/ F6 W3 j# j6 m2 X: M) T( Z5. return 1;
+ Q8 e2 p2 P6 I; t5 J3 h6. }
4 i( i& ~; q6 H4 y# N( m7. else if( x == 'S') return 3;9 m" c, u, l9 s. n+ |( V
8. else if( x == 'U') return 4;/ V5 p! {2 A7 v1 I3 l7 l! m/ J3 }
9. return 0;3 O5 h# G& s+ }
10. }( p& P' s1 x/ J7 [+ B# A& m
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1% Q' S! i' D3 Z$ K
A.‘X’
3 E' }$ b1 J# |3 @- h0 q# ]2 _B. ‘A’' a2 l+ X* y& {$ C1 q3 L* t% V" b
C.‘D’+ o7 K) C+ `3 W. A; K
D.‘Z’# n3 s& x6 X9 i6 m) A1 n
15.        读程序:
4 ~% @# U7 x5 p1. class TryTest {
& {: h/ P' f6 D! o$ e2. public static void main(String[] args) {
! H* e( q) m/ J8 U/ a8 p3. try{: e' A: m8 w4 K6 J% n) y
4. System.exit(0);/ n1 |6 {2 x6 @% J
5. }
7 H& h" U* G2 r" B; |3 r6. finally {" B" i8 q3 l" h- u) f" n
7. System.out.println("Finally");
; k$ L  W, W2 m, P# k: r8. }5 |: M5 ~: _9 ?# e$ G
9. }
4 X& Q3 ]1 j$ _; D7 m/ ^10. }
: f. a, r. @; }( u, w当编译和运行该类时,将:7 ?: X& l  D9 T3 c$ n0 l7 ?
A.程序因为第4行出现编译错误/ b% b6 C* i" h
B.程序因为第4行出现运行时错误
) }  s6 E  S' DC.程序因为第6行出现编译错误
* E* G) S# `6 r; @. fD.程序因为第6行出现运行时错误$ b! x& b. A8 \2 ^* @6 u9 ~
E.程序输出“Finally”
6 u6 u8 b6 a5 h0 a" ?& nF.程序可以运行,但什么也不打印
& `/ v! f& W  [! `, `3 G) R. m3 i. m  z+ Z- d4 y$ d
16.        Given the following variable declarations:! A& D0 _0 V) y5 i
Boolean b1 = new Boolean(true);
, D) g/ B& b. u+ {% C+ nBoolean b2 = new Boolean(true);0 }4 A' v2 {' k# k# x
Which expression is a legal Java expression that returns true?
: @6 C9 i- Q, f, x4 m5 XA.        b1==b2; ^" k5 _% q5 C' y) H* R( Q
B.        b1.equals(b2)0 P6 t4 ?( X0 K; o, B+ A
C.        b1&&b2
. a& ~+ ]) e5 p, E3 Q. CD.        b1||b22 M4 y0 b6 [( F5 N
E.        b1&b2. `, e# M  O( M, a' a% S9 I
F.        b1|b2
* O( T/ {6 ]$ v) o17.        Given: ; V$ E3 ^: j7 @% _6 |- L* s- R
1. public class Employee {( s  M3 f( h& r$ |8 ~: C, s& ?; z
2. ( z  Q; q9 a" |
3. }) E( @0 Y6 ?' w4 Y  f7 h) S; k
4.
& O& d8 B; P2 S. \0 U/ N3 S9 k* J5. class Manager  extends Employee{
+ I8 i; p& {. Q6. }3 J1 J! ]5 @1 `4 ^8 ?8 T
What is the relationship between Employee and the Manager?
- W6 i' h* A! `+ ~: A0 g, dA.        has a& M% c3 ~/ M& j2 S
B.        is a
9 m- L* k+ I# \C.        both has a and is a8 |, V7 n0 R: V
D.        neither has a nor is a1 q. d; w! w+ j
18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
+ a! r7 ~0 s% h0 ~A.        BorderLayout1 ?9 F6 W4 c2 `  b
B.        FlowLayout
* y* Z% }+ Z2 M- C/ NC.        CardLayout
/ t% _: H: A( O# w% z/ R8 U4 xD.        GridLayout
3 n: H7 S1 o/ K5 S4 {) u19.        Which of the following AWT components can generate an ActionEvent?0 l0 l2 x" M  J" ]; l& M! {" u6 u
A.        java.awt.Button
9 u0 t3 \$ \1 V) RB.        java.awt.Panel
8 I. V) i4 H+ }" w9 k$ yC.        java.awt.Canvas# T9 G2 A; G. X  Q5 \
D.        java.awt.Scrollbar1 L" U0 [& H% r% a" e2 c) f
20.        What kind of Stream is the System.out object?% k3 s2 t" J% w0 U1 p: D$ ?
A.        java.io.PrintStream
: I5 l" d) t7 R6 C6 {9 AB.        java.io.TerminalStream8 j6 P/ V- s' m+ R
C.        java.io.FileWriter3 N7 R; e9 T2 N1 W/ I2 P
D.        java.io.FileWriter
& w, e% Y7 v" M% C* s21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)) L/ l2 a$ e" G8 W! k. x
A.        java.awt.event.FocusEvent
+ X5 O0 N- _0 r6 B7 X: B3 qB.        java.awt.event.KeyEvent
9 ]  L0 L8 g! W: o# N& I% DC.        java.awt.event.ItemEvent
8 P" m+ C9 {' v7 mD.        java.awt.event.ActionEvent, z: E3 l1 K3 w% d
22.        Which of the following methods are static methods of the Thread class?(双选)
% o- j( D% `+ r& p0 WA.        sleep(ling time)
, j" E. y* p* }  |7 K' ^* N: UB.        yield()" R3 ?$ z* Y( C4 y4 M: s; S% q" K
C.        wait()$ l- K1 Y: b1 [' X
D.        notify()9 t* c! l" O1 |) j
23.        Which method do you have to define if you implement the Runnable interface?
% U8 N0 E- f; E3 ~8 `7 rA.        run()4 \( I( ~' t4 X0 z3 w' ^2 K# E' J$ b! w
B.        runnable()
! ^: q2 n$ K2 b0 p  N) t0 R( V/ iC.        start()" D$ J8 ~& x. U/ W: {
D.        init()  J2 {/ a4 \; X% c3 V  M: l
E.        main(); B4 Q  [3 K' B! u* C
24.        Given:$ f. G, b5 v, d# A
1. class MyThread extends Thread {& {3 G5 Y3 t( L+ z* c
2.
- r6 T$ n) v' B! x* ^  c; b# v# Q) X3. public static void main(String [] args) {
. T5 J. P. l1 C0 [4. MyThread t = new MyThread();
, J7 [7 w1 Z8 x& b5 T- @# Y& C5. t.run();) D7 n5 t: b8 T8 @: U
6. }1 Z( o5 x6 G. B7 n, Z
7.
$ l2 \0 @; N7 y1 j3 `8. public void run() {
5 x( N" }1 R# ~) U: F/ g* {9. for(int i=1 ; i<3 ; ++i) {& }* y5 N- {# ]; X$ g5 u. Z
10. System.out.print(i + "..");
4 S4 L8 h. B0 X7 @1 N11. }
" n9 m8 w3 a8 L7 @7 O. v/ C12. }
6 n% ~% y; T! }' G9 _2 a* N13. }
# y# W' g  I; P0 ]# aWhat is the result of this code?C
8 ?  c- c8 h) G, E% }A.        This code will not compile due to line 4
9 ~% \+ b  H1 M; OB.        This code will not compile due to line 5- d5 d' `. G; ?- W
C.        1..2..
2 c: T6 o1 T6 ^" J8 Z* tD.        1..2..3..
! ?, Q0 d6 `$ }25.        Given a local inner class defined inside a method code block, which of the following statements is correct?
; x# l% q- [/ o. `' pA.        Any variables declared locally within the method can be accessed by the inner class
3 D- g0 S( t2 y; \2 p5 hB.        Only static variables in the enclosing class can be accessed by the inner class) D- A! l+ W. H  g+ A" o1 f
C.        Only local variables declared final can be accessed by the inner class6 Q# B6 o* D5 Z, f( R
D.        Only static variables declared locally can be accessed by the inner class., x" `3 a; P9 s, P% Y2 t
4 F: }: D2 i' \

: n6 W* }1 h' Y! n- E! p* r1 W& q! `+ l1 R, q! f
26.public class SychTest{
" L/ L: s% a" y' i   private int x;
, V& {* E' n& G- h: |+ ~   private int y; 2 G. P1 |4 a: M/ A/ A0 }. h( Q
   public void setX(int i){ x=i;}
( E0 f& D. |& @/ x% D% y, g" r   public void setY(int i){y=i;} 3 O! D+ R' {6 {6 ^+ C
   public Synchronized void setXY(int i){ & ^, c2 e& q5 S8 g2 B3 I
     setX(i); 8 q- d& k6 J  l* _
     setY(i); 4 {- _+ }) @5 |" Q+ Q$ m; U
   } # d! o: N: P  ]' I& A4 J. s
   public Synchronized boolean check(){ * _9 f; z6 j) ?- P
        return x!=y;   
0 \" f- Z1 i1 Y3 }: q* F& y   }
) B$ [/ Y. `; c* D& D- M( s   }
2 V# Y0 E) J  Q    Under which conditions will  check() return true when called from a different class? # R# P4 h  ^3 G$ m  |2 G2 ~6 s% ]
   A.check() can never return true.
: R4 p- J* F: k' y0 S   B.check() can return true when setXY is callled by multiple threads.
! v9 i- N- R& E! H/ f( Y# k   C.check() can return true when multiple threads call setX and setY separately.
' ?4 @3 i2 M: D) y/ o1 z   D.check() can only return true if SychTest is changed allow x and y to be set separately. % G( [* \/ {9 g1 I) A. B! F+ q
3 G# f1 j+ d: l* ^$ p
27. 1)public class X implements Runnable{ : A1 g. d. I+ [2 q
  2)private int x; : t  `1 w) {2 O/ Q7 R
  3)private int y; - l7 D! }& M0 @( t; [5 c# S
  4)public static void main(String[] args){
  M2 k  \5 d7 |4 |" m5 b  5)   X that =new X(); 0 Q4 n6 L3 }: C4 @# R9 D% |
  6) (new Thread(that)).start(); 9 v7 y  B8 X' n- l# J$ T! @
  7) (new Thread(that)).start();
& Z. t8 v& Y$ @4 e" \: T   } # f! s  i: v5 R3 b* s
  9) public synchronized void run(){ 4 J3 l% Z; Y9 Q
  10)  for(;;){
( X8 Y+ ]5 g4 ], @- Y2 [8 C# D4 k% a  11)      x++; + I; g# K" Z1 g, L  \, M
  12)      Y++;   o% T2 b9 H8 J/ H, S8 x3 U" F3 k
  13) System.out.println("x="+x+",y="+y); 2 H/ i& z: O7 u5 `4 z
  14)    }
) V+ P! h& P* f- e  15)   }
+ @! Y8 O8 B; `# N& a: O  16)  }   8 R  K/ ?$ h* u: A7 ]
    what is the result? 3 i# K+ a: U' Z7 G  i
  A.compile error at line 6 3 d" T0 _( N" i, z# g4 w' z
  B.the program prints pairs of values for x and y that are
# E& t+ V, H! V* U4 P    always the same on the same time
1 s5 N5 k3 o& p8 n  p
) T. ~* O- K8 t/ u# `28.class A implements Runnable{
0 G) F& }( W# t' v9 a$ w% p( l8 x$ ~; r  int i; , @- `9 |9 u0 j  U* _+ B: H
  public void run(){ 8 R# D* f7 D. b! L+ g
   try{ , j' ~) X- K! |0 G5 p
       Thread.sleep(5000);   ?0 O7 Q8 W5 x& Q* t
        i=10;
! M2 P( s' ~2 U: O       }catch(InterruptException e){}
; K) V3 G9 U( n  D1 O8 u3 E       }
4 y4 a& O0 `% p       } , ]% H$ w( z& b
   public static void main(String[] args){
" f5 o! a* v; `+ A      try{
% E! K' v: r( f# D0 [' O         A a=new A();
/ o; E$ J( t) Y         Thread t=new Thread(a);
) p; w$ X/ a2 K: m9 ]- a3 |         t.start(); 1 g, r  E( k% |0 U
  17) ) x1 J! Y2 n) r2 w6 T2 i
      int j=a.i;
% I# G. ]& [3 R9 v5 r5 I9 T$ j1 D  19)
0 X  u1 k! ]9 W5 G/ h$ u6 _      }catch(Exception e){} 9 r- t3 y! z2 `& ]2 H# d4 M
      }
& T' ~; R0 v% C6 B      } 8 n1 l  @% `2 Z& I
  what be added at line line 17, ensure j=10 at line 19?
6 u" |  {4 T' C1 X# }  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   # M9 S/ ~; x& F+ R2 I5 W. `: N
  E.t.notify();  F.  a.notify(); G.t.interrupt();
' i, Z( x- G9 ~* C* d  C  U; D8 @! {29.1)public class X{ 8 r% v5 y4 `7 a* J4 y
  2)    public static void main(String[] args){ 7 K9 I) U+ |: |. s$ \; x
  3)     String foo="ABCDE"; 8 Z. ]; E) G* ]" @# l& _  h$ o
  4)     foo.substring(3);
# L, ^: ^$ n2 g* n  5)     foo.concat("XYZ");
- N2 \# s$ h* n  6)    } % ~" t2 [4 W9 n' N8 Y
  7)   } $ S, Z0 z  a4 ?0 U
  what is the value of foo at line 6?
: r; J- u' M% `3 B& ]30.  public class Test{ " F" p1 G& N" m2 Q0 C
   public static void main(String[] args){
' Y9 A7 q; j7 j: C/ |   StringBuffer a=new StringBuffer("A");   e# P/ ?( v# F3 M
   StringBuffer b=new StringBuffer("B");
/ y7 ?% }* E4 \+ t( x5 \  O0 ]8 w   operate(a,b); $ H8 b) f, }. u8 d) P( N
   System.out.pintln(a+","+b);
& S: _3 J/ K- g' ~; ^4 ]9 ^    }
# C+ A$ |) c8 z% Q" Z   public static void operate(StringBuffer x, StringBuffer y){
2 C) D! i) t* e1 h" [, Y; S    x.append(y);
. M/ I) ~! R7 Z& Z( I1 w  O    y=x;
3 j0 Z' o" ?/ S. ~" d   }
) }$ f! k$ O0 l' }- A. O   }
. Y+ ^6 o# B0 d   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享
, O7 ]- O( l" k/ B% V  z( g: w- f我已下载。。。。。
0 K  A  V8 d3 q& T( k特感谢您的大公无私
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-23 00:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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