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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题
* P+ ^$ B0 d' g9 ^& T/ p1.        给出以下程序:4 D; h9 X4 W8 ~2 f5 F, E( K. U/ K
1. public class Colors {
1 ]* x% R1 z  a! \. R3 f% E/ g2. public static void main(String args[]) {, `9 B7 d9 K) k6 U3 a/ [! U
3. int n = 1;
! U; u& M: V, ~! A/ w* K4. System.out.println("The Color is " + args[n]);
- g: X( m- f) O0 x2 x4 z5. }
" ?- w/ z2 y( |; Q  {6. }
) W7 Z# _8 v8 K1 f假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
! s+ B3 ]! `7 \A.        Colors red green blue yellow
6 O( F. y! _. F0 W7 E  XB.        java Colors blue green red yellow- h# C9 s1 z% I6 _' Q% V
C.        java Colors green blue red yellow% B) R* s1 e  j; `2 Q
D.        java Colors.class blue green red yellow
5 P/ |6 q4 G% z; S0 b6 Z5 X. lE.        java Colors.class green blue red yellow' @; A$ Z5 C( r
2.        读程序:. N* \1 v$ d4 {9 I
1. public class Test{; u0 H3 M# U6 p* X/ l
2. public static void main(String args[]){
5 G) P1 j2 e" O8 p3. char c = '\u0009';# ~0 C( a4 ?' `% D7 n. O9 _# W' r7 M
4. if( c == 0x0009L)" z! N: H: Z9 E7 ^3 }2 A* O
5. System.out.println("Equal");) J9 u/ ~% k* X/ R3 C! D
6. else System.out.println("Not Equal");
) _+ l4 e! m1 N( S7. }
7 e! F! m" `! l8. }
9 |) y; l& |# G8 M当编译和运行该类时,将会发生什么:
% F% S/ N% E7 YA.        程序因为第4行将出现一个编译错误2 m: \+ z# {2 c
B.        程序因为第4行将出现一个运行错误
5 m3 n0 V6 S& O% A3 d+ }1 _7 T5 OC.        程序因为第3行将出现一个编译错% V7 O7 n* Z5 U/ u$ R* c
D.        程序输出”Equal"
( R1 x, s; w! y; _. n/ PE.        程序输出"Not Equal”
: l$ Z3 p: u) h# b3 G" c  i3.        读程序:4 E+ x0 U; F) Y1 L) z
1. public class StrEq{& V8 l2 F9 m" N  l4 R# g
2. private StrEq(){6 b: U8 f+ V) T5 h$ X- B
3. String s = "Bob";
: X, d  V# w- I* l3 K6 ^( \* H4. String s2 = new String("Bob");
6 G! w3 b) k: c( }% U5. if(s == s2){
( m9 Z( `6 s! |0 P# R* d, ]6. System.out.println("Equal");
. Q" \+ g0 T' V# M# s7. }
9 y) H0 g/ x; N3 ~5 [; K8. else{
6 R" j! f1 J8 j7 r, L9. System.out.println("Not equal");
; u  D, F  ?, k% q9 ]4 J10. }
9 T, Z" ^& J7 m4 m" Q11. }- D4 R: v3 t/ k& c  A, c- \
12. public static void main(String args[]){
  r6 f% e# z( e: m8 X4 q5 Y9 ~$ P13. StrEq s = new StrEq();0 ~- n  H; Z9 B$ m. d- y" e
14. }
( q$ |9 L- R* q8 S5 g. ]15. }
) m+ k+ Z5 u  a+ k1 T* k当编译和运行该类时,将会发生什么:
; a: Y. [3 A) p# q' _A.        程序能够编译,并且输出“Equal”# f; }7 ^- J9 [/ {" P
B.        程序能够编译,并且输出“Not equal”
6 s3 u0 j) b( ?8 e# N8 HC.        程序因为第2行导致一个运行时错误! B& q7 |! X9 x7 f: R: m
D.        程序因为第2行导致一个编译错误- h/ Z! }* T& Q' R  N7 s6 J/ `
4.        以下那个赋值是非法的:8 D9 B5 Q/ m% ^3 P5 j+ H
A.        long  test = 012;
9 H$ u& G  `% O8 FB.        float  b = -412;8 x4 T8 N, C$ }& P
C.        int other = (int )true;" c1 j+ v# ^% ?' C# s' J6 t7 E
D.        double d = 0x12345678;
" f2 c7 P3 T$ |' a+ T4 u+ ZE.        short   s = 10;( q4 k7 N8 x- ?
5.        读程序:
! }9 k( \. o6 i  z1. class CompareString{
. ^- ^6 A6 B1 b, x1 R* u  U/ T1 I7 g9 _2. public static void main(String[] args) {
# }6 S' [6 e! m+ P3. Integer x = new Integer(5);- R* a' t6 d& C7 E2 n: a# j) G
4. Integer y = new Integer(5);
4 W5 K( a/ {5 i3 A$ A5. Integer z = x;) [0 _. q% r3 F" S$ {
6. if ( ______ )
/ Y& G! w1 K% X: p' @" N7. System.out.println("true");
  E3 b4 _6 F# |. u2 {8. }) o! {+ r, F$ i# a
9. }
+ C7 g6 c- K7 F9 B, R; I9 H以下哪个选项填入第6行后,不能输出true:  o$ }8 l3 U" \/ O; `5 {0 q
A.        x==z; n1 n2 }& l  s; ~
B.        x==y
) [1 |1 R( b& ?" A; E& |3 O. AC.        y.equals(z)! {0 B) o8 ~# q7 X+ F8 f1 l" c: Z" R
D.        x.equals(y)8 W! @8 U2 q) |5 P! w
6.        读程序(双选):' e7 j9 |" k2 `; Q+ X3 X
1. public class Declare {. W' F/ M3 d: Y! D+ W* u6 x
2., v' S& r9 {+ r- h$ C4 o; k; [
3. public static void main(String [] args) {: n# m9 z; Y5 I% }0 ^2 m+ s; O
4.3 _! Z9 s6 K" }6 {6 r
5. System.out.println("The variable is " + x);
" J8 I* t9 J& W& v; Y, ?- t9 z6. }0 f0 y4 ^+ X  }# k- \# W
7. }2 Z& M4 w" p+ k5 ~' B& W2 `+ q+ [
以下哪个选项中的代码可以使程序编译通过
$ i6 Z9 s; J0 m: N5 q  JA.        把“int x;”放在程序的第2行- c7 K  q+ A$ \0 Y
B.        把“int x;”放在程序的第4行
* j; Y! R6 c- hC.        把“int x=5;”放在程序的第2行1 _: S! E2 Z, l, R
D.        把“int x=5;”放在程序的第4行, W4 h; O& H# K- X% D
E.        把“static int x;”放在程序的第2行
& m! k5 T& w* E, C( J" F5 U  Y8 D) M2 w6 A; u3 _

3 G/ H$ [9 r1 ~$ _5 w6 c) o1 E& \7 t. Q4 V1 v! J
7.        读程序(双选):
, R( o  u- ~7 R, d1. public class Child extends Parent{
( D! z0 n- m7 _9 D, q/ J; b2. int a, b, c;
) n3 a  m1 z+ H& P/ m3 T0 ^3. public Child(int x, int y) {# L' a& F1 E' W2 L* p) q1 r+ t9 ?/ \; ?
4. a = x; b = y;
) c1 V, U) V" ]0 v5. }
2 x! ?' Q7 a* \! u# a' t) q6. public Child(int x) {0 O8 Y$ c9 Q3 L$ y/ ], v1 f
7. super(x);1 }' ?+ G: p- ?
8. }$ \% z9 ^' N% m
9. }0 @% |7 c4 Y7 I! Q
为了能使该类编译通过,下面那个构建器必须出现在父类中:
  b( b$ x* l: ^! _- TA. public Parent(int m,int n)
7 H" O& {' @& i" [B.public Parent(int m)
; D/ s% w. y3 v8 ]1 G# QC.public Parent()6 T- |' |, c/ V2 L1 x% E3 K9 j
D. public Parent(int m,int n, int o)
3 R2 _' {  ^8 ]0 N3 X# Y8.        读程序:% @  K* K( m% x# c7 j
1. public class Derive extends Base{) u% O- t: b7 J, V2 u5 c, r
2. public static void main(String argv[]){
( `/ g8 Q7 ?( _% \3. Derive a = new Derive();  B  {0 {, h6 }1 N1 g9 k# V
4. a.method2();
/ }4 w; k- h7 v5. }, N) n6 a! e; Y
6. public void method1(){7 j3 K" g0 ~; l- s3 Z( A
7. System.out.println("method 1");$ D( y4 w: a) m$ J& i
8. }
7 s0 r# ~% G' S9. public void method2(){! L; ]- B3 Q+ p2 m7 h4 J/ Z1 J3 A
10. method1(); # X6 U- E# M! L3 E0 s4 K% g
11. }2 c3 l& R0 Z1 X! s3 p3 u
12. }/ |5 [2 ]6 m+ ~0 g7 i4 v. o
13. abstract class Base{( o( H; i: T- u- d* `
14. abstract public void method1();/ g* y+ l3 G  s  a# x2 Y" k# v
15. public void method3(){! r3 S& `+ {# C7 L( K: \! v
16. System.out.println("method 3");% O) [: A- q2 j* R- n, b/ K! E
17. }8 I3 A3 @4 C# Y) C& Z4 x3 y9 T; C
}
- e6 G+ Y2 d4 C7 d2 f& x( U6 `当编译和运行该类时,将出现什么:
& ?& E% z8 N7 \$ a, Y6 cA.        程序输出“method 1”
/ F6 M$ J/ o, ]% P( [: ?B.        程序输出“method 3”
& i* `" i4 R7 ?* T$ uC.        程序因为第15行而出现编译错误
: K1 o: F  a' U4 H6 `& r' w# [+ DD.        程序因为第15行而出现运行错误! W  ?3 Y! l$ ^7 ^
9.        以下哪个接口的定义是合法的:
! f7 s+ m4 q% @8 T8 ]A.        public interface A {int a();}* {! m" Q% Q8 p3 N
B.        public interface B implements A {}# Q. ~' G8 v  N) ^" ]
C.        interface C {int a;}
9 b$ a! s, h' S) H: Y2 vD.        private interface D {}+ ^2 v! ~. |$ U* e3 V
10.        读程序:
2 D( W1 L: u$ n# V1. //File SuperClass.java
5 v9 |$ v: ~1 j6 J2. package MyPackage;3 S( Z. ]: K# b6 d% Z. d- G: T
3. class SuperClass{. ]$ I& J, x4 ~5 b
4. void myMethod(){* y, g/ H$ e; `) z$ l
5. System.out.println("SuperClass");- R" B  f; v5 a  `% z  x
6. }$ m: W, F' W, Y) K
7. }. K0 ?& T; l4 q, j# f6 u
8. //File SubClass.java
3 {- u+ [+ K2 X, h9. public class SubClass extends SuperClass{2 v3 h: K% G1 d
10. public static void main(String[] args) {9 v' _& J1 H) Y* ^! c* y+ L+ M
11. myMethod();1 K  @' l3 c6 X' Z! ~7 _! z
12. }) P# i8 F! \2 `0 S3 q& l( U6 ]- k
13. }& ]5 D# F3 H$ ]
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:, n- g& B" l7 Z2 @' Z& @
A.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
. X$ P6 I! Z  t' A# Q* W6 wB.        两个类都回出现编译时错误
# M/ M1 a, P4 \C.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误7 f3 R$ _" q0 ]2 A
D.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误
" ?" d/ b6 [8 i11.        读程序:
  z6 J4 r+ D: R1. public class Test{
* O  i8 j/ {. O2. public static void main(String args[]){
4 [/ t3 b( n& Z- z7 [3. int[] i = new int[5];) q( B- {6 i% |# z1 e
4. System.out.println(i[5]);; J5 x0 M) j, i; `
5. }7 ]; s4 b; h- B; ~6 V- M
6. }
% ]0 V/ L6 e( ~) z当编译和运行该类时,会:
  H) e) [/ {$ E$ t: s2 mA.        出现编译时错误/ b# W4 Y1 z4 x: C
B.        出现运行时错误4 e; I) T; b8 I+ g
C.        输出0
% c1 [/ p. }4 eD.        输出null, V6 T1 X7 k. K" {& [' ^
12.        以下哪个选项是正确的数组声明或初始化:
, P2 I+ |3 D; r; U4 q$ H0 U6 s1 X" bA.        Array sizes = new Array(4);3 C5 ?" m0 _0 f+ D9 V+ ?' s3 N! [# [
B.        double [] sizes = {1, 2, 3, 4};* g/ y% o, T3 Y* Z/ Z4 n$ N
C.        int [4] sizes;
" J2 z+ S1 [0 `* pD.        long sizes [] = new [4] long;
# e$ e* \+ e- i" E; k5 T* W+ R13.        读程序:9 T; ?% ^4 k$ t/ H( S
1. public class Initialize{
" \- i! g) [6 f2. int x = 200;2 x; H! Y1 y' H: {8 q) u; o
3. static {
7 V; O1 @9 ?% H2 j4. int x = 100;7 C0 r$ h/ ]* `
5. }3 j: I/ @$ ~3 e& Y  ^5 S
6. public static void main(String[] args){
" u' C6 k2 q) X9 ]% i1 s$ F7. Initialize init = new Initialize();# O5 H1 e9 [- |+ n+ w
8. System.out.println(init.x);
4 h2 ^: \* S# T, t/ Q( ?) m5 I& C9. }
4 R; P- o" B1 b  ^8 U* V- c10. }
& Z5 g' ?" V) i" y' O当编译和运行该类时:1 M4 c7 t2 [7 p9 @$ `
A.        程序因为第3行产生一个编译错误
: V/ t) h7 P0 o; h1 y8 ZB.        程序因为第4行产生一个运行时错误" p; }2 i# ^& ~  x* ?
C.        程序输出100% h" T- E" @- K
D.        程序输出2002 |9 m8 W; m7 P$ U( r! M  _* J7 j
14.        读程序:
) G. C- W& B" R8 t3 W% A1. public int abcd( char x) {: b2 u. p0 |+ }2 _- n
2. if ( x <= 'M' ) {& c9 ?5 _1 g/ x5 k/ A: p
3. if ( x == 'D') + x) @0 E* u4 M' T; j! s) k
4. return 2;
& t" m" y. a8 w5. return 1;
% y$ o5 a0 T" }+ M) q- X# x! N6. }; C- a$ d1 K: r& N! b3 ^9 b
7. else if( x == 'S') return 3;
' S' s6 U5 N6 E  R8 Y0 A8. else if( x == 'U') return 4;) \: }- c+ E/ J3 o; q
9. return 0;
$ K* D* ?* y! u3 ?10. }
! d0 t6 {, |' _6 a% ?0 u在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
; F3 W3 T) {6 b7 v, u' JA.‘X’
/ e7 \. c9 h& s0 s* ]B. ‘A’- _4 W1 H" u( Z( w' \: `
C.‘D’
7 Y, Y, P- b2 Y# G3 r9 ?, ~* m# iD.‘Z’
: O5 U3 J# b; V* Q15.        读程序:
  r, r: N. y- h0 Q) u  t( j1. class TryTest {
3 j% s, X6 ]  e5 ?' ?$ y2. public static void main(String[] args) {
" _) @# ^! d2 _3. try{
' D9 P0 R$ G; N4 j' A# e4. System.exit(0);
1 z/ t) c) x9 {; l( j5. }9 Y" ?& F" |' S! r
6. finally {
6 {' F, I! F7 X  v% O7. System.out.println("Finally");
1 ]- v# s9 d/ n# z8. }, k* P( C; J$ _: Z3 O: S- `
9. }6 ?9 Q5 @1 M5 ~2 z
10. }. a1 t! L- m4 j4 Q2 H4 O1 P. Z
当编译和运行该类时,将:
- F* W6 d0 n: Q3 `5 e9 sA.程序因为第4行出现编译错误
+ L1 [: K: G8 w) E3 m# TB.程序因为第4行出现运行时错误
3 q+ [+ a9 l+ v0 u' JC.程序因为第6行出现编译错误
" C1 P/ _( ?3 |* E2 ?8 w7 pD.程序因为第6行出现运行时错误
' o6 `+ d# Y0 ?- I" `8 {E.程序输出“Finally”7 N$ O* M: P( j# p7 m+ q
F.程序可以运行,但什么也不打印
7 Z3 d: h5 `# c3 E, a; j
7 P. T. m: p' z' W: a' v16.        Given the following variable declarations:
( ^! O( C3 e- p4 OBoolean b1 = new Boolean(true);4 c$ ]& h: R! {  Q6 `
Boolean b2 = new Boolean(true);. H( X3 {, ?! E8 Y6 v4 J0 y/ D
Which expression is a legal Java expression that returns true? ! G/ X' U& L8 ]
A.        b1==b2
7 E; Q1 S7 K2 Z6 A& VB.        b1.equals(b2)
6 X. A% N! \( v" b4 f+ zC.        b1&&b26 H, n7 r) x/ q( r
D.        b1||b26 Y# w2 }" i4 l5 k6 {
E.        b1&b2% ]3 Q0 `$ Y- q9 l/ s" W
F.        b1|b2
/ Z, Y3 `# b  W17.        Given: 5 `6 `7 q/ R. M" g- h  O
1. public class Employee {' a9 B' x1 \! l2 P! K3 E
2. - l, }3 S2 E1 C& G
3. }
+ {9 {  h2 ?/ P+ B0 I9 D6 i4.
* S7 ]. b8 y/ F5 N8 r7 _5. class Manager  extends Employee{6 Z  ?/ j9 H0 L+ w$ F6 K
6. }
2 u5 x" e: _# {2 u' `( S$ z- F! RWhat is the relationship between Employee and the Manager?
+ H8 d! t- e$ H$ gA.        has a
/ Y2 u& y7 p: N: p! V: RB.        is a
5 Q/ t! k4 y; s: h5 H& f2 a! {2 SC.        both has a and is a
% ]: b3 S( T* x1 U# y8 y$ VD.        neither has a nor is a4 X8 i  n- s5 ~" z+ ^2 m/ P' t, [
18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
' M6 J" C, i# d* KA.        BorderLayout" O/ h2 |" R, l/ ]
B.        FlowLayout6 x& _: ~) q# K% v( S
C.        CardLayout
3 L9 v  X' `+ F& j8 C- D# b* pD.        GridLayout
5 N5 k9 A1 b; e: J2 V$ ?" P1 w19.        Which of the following AWT components can generate an ActionEvent?
6 V: K7 ^+ h3 C2 M  w# `A.        java.awt.Button3 m) L$ f6 [9 a, N7 v9 v
B.        java.awt.Panel! d% ^7 z/ E2 |( \
C.        java.awt.Canvas* a0 u- s. @" K7 j5 u
D.        java.awt.Scrollbar
2 n& w! M9 o# [9 e; k: R1 ~* j3 B1 X20.        What kind of Stream is the System.out object?
5 [* ?2 g& j5 u+ z) M9 CA.        java.io.PrintStream. I; X9 S# i# Z& m+ Q
B.        java.io.TerminalStream
7 f! d) z- x! V1 t6 @$ k5 R2 `1 S" gC.        java.io.FileWriter
% p6 C* I& P- TD.        java.io.FileWriter. I2 a% L4 B4 r
21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)
' N/ O  P% j$ V. }7 c5 s9 h- x# RA.        java.awt.event.FocusEvent
, P; W! z& z8 ?B.        java.awt.event.KeyEvent
9 \+ Q& U3 f- h" PC.        java.awt.event.ItemEvent
* h/ G% Y; p2 QD.        java.awt.event.ActionEvent7 C: h7 _7 Q5 y# h2 L  X
22.        Which of the following methods are static methods of the Thread class?(双选)$ r  S; w* ]1 e
A.        sleep(ling time)
6 o& `7 ]6 n* u0 t2 zB.        yield()- ]8 |( v9 r. J
C.        wait()$ ?' U5 z9 j5 g. m' s, B
D.        notify()
0 _, u3 F( C+ k/ v7 `# ~23.        Which method do you have to define if you implement the Runnable interface?: N' E1 d6 K+ R! R+ G
A.        run(). B2 m& }3 V$ F/ n
B.        runnable()
2 o$ N. L* t  ~; Z$ u* A+ I: MC.        start()# a* g4 U! J& k9 D8 y
D.        init()
' D# q9 @: g6 x, QE.        main()% X6 l* x: N" f
24.        Given:
7 s' ~7 t( W1 W: y+ i: ]2 {0 G1. class MyThread extends Thread {
8 n: y3 q0 W8 m7 l2. 3 l6 f- ^: L/ w7 ~; ~0 |4 o
3. public static void main(String [] args) {
' O% Z, E0 ^- l" A. z- a4 G4. MyThread t = new MyThread();
; i! ]+ }9 M( `% ]3 {& a; g5. t.run();
* k* I' V! p" c" d1 P& P2 s" A6. }
$ o7 V  K9 W5 y- S! B- d2 G# `7. * B0 B( B8 r! m
8. public void run() {
$ G( e" g3 w$ V9. for(int i=1 ; i<3 ; ++i) {
. h+ D7 f( Z: a! ~7 ^" b, _$ @. `9 t  K' R+ g10. System.out.print(i + "..");4 r' u. d$ ]0 Q, S$ n; L& y
11. }
) W1 I/ S% _0 m/ `2 r12. }' W, n* T3 ~- F9 p
13. }8 _8 \5 H. t/ H" W5 ]( [
What is the result of this code?C/ T, c0 X3 I. o: K5 c
A.        This code will not compile due to line 4. O! T0 K! G4 D- `
B.        This code will not compile due to line 5
5 X- l7 _$ J2 |1 tC.        1..2..$ i% A% R: C5 s! V
D.        1..2..3..
# r. I8 p6 w9 [" o$ I25.        Given a local inner class defined inside a method code block, which of the following statements is correct?: F' ^  `! g' \8 z
A.        Any variables declared locally within the method can be accessed by the inner class
% J- ~% X! L( o( w+ |' hB.        Only static variables in the enclosing class can be accessed by the inner class; n) L# B2 z  r9 v) h. f' `, E
C.        Only local variables declared final can be accessed by the inner class2 M3 [- }6 j# ?$ X' O( L/ T
D.        Only static variables declared locally can be accessed by the inner class.
2 p" ~1 j% v6 x& B, W/ q. O
4 X. b7 G8 _( g- r. p& y9 C4 L' f( ?* \

1 V, b* B0 h6 Q  y6 W26.public class SychTest{
1 G4 v; |! i. y, ^   private int x; ; |% ^- f/ x* _& @( l: H" H
   private int y;   j  S2 r) Q: g1 q
   public void setX(int i){ x=i;}
/ c0 T+ F; U  s2 y; I, U   public void setY(int i){y=i;} 5 X2 J" a3 a7 l4 U# n7 p
   public Synchronized void setXY(int i){ 4 @% }# F0 p* |. W) e
     setX(i); 6 j9 ^6 R' B0 O+ k, S
     setY(i); ! v% z. S2 e( T4 O' W  W
   } 4 Q) s# z3 _! J  G/ ?  c
   public Synchronized boolean check(){
" w: @1 G9 j: M1 E# }        return x!=y;   
' M* X$ a% \8 a/ \7 V; \5 S   }
& _) S" [( f1 a   }
; ]3 z2 \8 e- W4 Q: S7 U    Under which conditions will  check() return true when called from a different class?
, M* v: J1 j# |  @' w/ K7 y( A   A.check() can never return true.
& p9 h9 k# K  D   B.check() can return true when setXY is callled by multiple threads.
- C6 L4 n4 q$ _4 D% `   C.check() can return true when multiple threads call setX and setY separately. & `2 \+ N' @% T; b; ?3 G, n
   D.check() can only return true if SychTest is changed allow x and y to be set separately.
( O# {9 H$ h/ G! A: ]  B$ _6 h: d
27. 1)public class X implements Runnable{
% n, l' G) E' w- U! Q  2)private int x;
8 A6 j' m/ M! }" F- }5 j! T  3)private int y;
# _3 ?9 f- d8 Y( s/ d; F8 y, E0 X, O& c  4)public static void main(String[] args){ 1 d( F& Z# N1 S; x6 U' G7 w
  5)   X that =new X(); ! K4 a- u( G* {+ b) ~' Q6 u
  6) (new Thread(that)).start(); 1 R, X: ]0 f3 Q
  7) (new Thread(that)).start();
( [! [- J% B2 M, s- ~% q! X/ w   } ' W( _5 P  p6 }- R8 x7 U! n
  9) public synchronized void run(){
# W( g. X' }6 `% I- ]* T3 n$ i7 _+ f" U  10)  for(;;){ 4 R# ~0 o- I4 U7 z  R
  11)      x++;
3 ]1 n) L' N( S* N  12)      Y++;
; ?6 y. n/ ^2 P  13) System.out.println("x="+x+",y="+y); 3 E# d: \' x* @  W  L5 P, q) R1 |
  14)    }
  k' l' u. k: N6 w  15)   }
8 K2 a/ j% I% e& D5 Z4 E5 |  16)  }     n7 j. v3 g, b* F) q9 U
    what is the result?
1 t$ ^  l5 e* D/ u  A.compile error at line 6 2 E3 T, v6 w3 \! y5 D' q" y
  B.the program prints pairs of values for x and y that are
6 |4 [- e4 A: m    always the same on the same time
* g3 {  J" N' a: Q# F, B
  T1 O. Z1 |5 }: x$ B1 ]: Z28.class A implements Runnable{
' k+ ~% w! t5 {1 Z4 a  N; P, D$ [  int i;
8 e; O; Y, z) q% R( f6 _  public void run(){
0 L" n1 u# w5 E& `3 e: g   try{
/ [) t; B7 [' `$ B       Thread.sleep(5000); " h; I$ D$ R5 C" |0 e1 A
        i=10;
- {: m: F0 U" j; M       }catch(InterruptException e){}
. I" _+ p% `$ m" R" E4 D) q# s3 n       } 4 U% s5 h9 ~: j8 p9 l7 Y7 S" x
       }
# U1 t9 W' Q! E  u3 E! p$ c   public static void main(String[] args){ ! U) R& K3 R9 _$ ^8 ^
      try{
8 h4 T% W2 R* u- I# m% F& V         A a=new A(); 8 U; b% M8 [. ]: W* c9 h
         Thread t=new Thread(a);
  W7 g" H+ `- s1 e0 k8 z         t.start();
2 c  \* ?, `+ P  I2 f7 y8 D1 N! t4 j  17) / @1 e) G2 B0 d  `. n9 v+ c
      int j=a.i; # t6 E. ?) Y! H4 k, Q( o
  19)
; K6 [8 l" w& P8 A      }catch(Exception e){} 6 q% W& ]9 F' K6 Y* ]. @. h: a
      }
2 a. a- \& @2 J) S9 H      } . Y4 O4 m5 Z, v8 O0 K
  what be added at line line 17, ensure j=10 at line 19? . v- g( n5 S" n6 X
  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   
3 S( F$ f, H/ `/ h/ ?' g  E.t.notify();  F.  a.notify(); G.t.interrupt();
# u2 b5 |3 I5 h" I# x29.1)public class X{
: ]# }7 [+ c' Y  2)    public static void main(String[] args){
0 K- t7 ~6 B) z7 D6 J9 o1 ], Q# x  3)     String foo="ABCDE";
. r4 @& i( x, O3 `+ P8 M  4)     foo.substring(3); 6 w( O; T$ x' M: X5 Z# t3 r
  5)     foo.concat("XYZ");
5 [! M' T. U- @0 c, g  6)    } ) y. b$ M, Y+ `' C  ~' e: x
  7)   } # o3 J# R$ ?7 y4 G) r% {
  what is the value of foo at line 6?
+ U/ l4 N8 ~1 u& Y+ _! B30.  public class Test{
& @) c6 [2 r" I9 g; d" h7 K   public static void main(String[] args){
3 S4 ~% P( o$ ~   StringBuffer a=new StringBuffer("A");
! i' Y3 G/ n9 v; l( a   StringBuffer b=new StringBuffer("B");
! v; |( N8 e2 O3 C: \5 M" ?) |! n   operate(a,b); # t7 q6 I/ J. L4 O+ s1 b4 |" h
   System.out.pintln(a+","+b);
' E& X4 f# u6 z2 t5 I3 j' z$ ~    } 9 ?+ h, ?& h8 O" c3 p5 h: R4 S; ?
   public static void operate(StringBuffer x, StringBuffer y){ . I+ u2 u& Q: E' s: h( [
    x.append(y);
) q! E/ Y1 \, @2 M# B9 U    y=x;
0 _8 e- v/ S9 N5 w3 j   } * T" M* `2 f, P
   }
* m& [9 ~7 t9 E) M3 `   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享7 E4 a8 u" E: X0 h! w/ U
我已下载。。。。。
9 U% _* O$ v3 W0 ]& i# m" S5 X* 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 10:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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