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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题5 `6 I4 D# c1 c
1.        给出以下程序:
- u( k' r  x& W* K* {% O3 M# l1. public class Colors {! G3 U/ h' i& W
2. public static void main(String args[]) {
8 F; C1 g. s0 M. z% u/ U, c' a3. int n = 1;2 P2 `% N- l$ z3 S% L6 X
4. System.out.println("The Color is " + args[n]);/ G4 V  o; o4 P1 h) G' V0 U
5. }: q/ {8 G$ D) H, m0 [( b: _
6. }
# i5 o2 O9 @$ }* N3 ~; B* H2 b假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”; i# k3 {$ Y- T0 k; s0 H
A.        Colors red green blue yellow! N" v' j, h% {4 Z$ J2 s
B.        java Colors blue green red yellow+ x3 R: E5 ^6 I: f5 N
C.        java Colors green blue red yellow) }5 y. v. s$ p
D.        java Colors.class blue green red yellow% Y% M4 u/ g, G6 c( Q+ ^, {! F
E.        java Colors.class green blue red yellow
% U9 e# X0 ?6 C# b( T9 c2.        读程序:
# ~9 e" \* p% ~6 c$ H/ c; O4 W1. public class Test{9 \+ k( W1 c  U6 v) j
2. public static void main(String args[]){0 w8 c# b7 r3 x& G7 M
3. char c = '\u0009';- r$ c$ `2 g3 i
4. if( c == 0x0009L)- N! V5 [5 C6 }5 U5 e* O5 Q3 _; g
5. System.out.println("Equal");
" N1 Y7 _! ?; E4 y( S% I# j6. else System.out.println("Not Equal");
5 p. B& ]0 F2 R+ B7. }
" W9 C7 {, E8 D3 k+ \; I7 Y8. }, l2 P6 @1 I; R4 V& {- K
当编译和运行该类时,将会发生什么:
/ T1 g& k& h+ X3 ]7 HA.        程序因为第4行将出现一个编译错误
5 w& J# H( l4 a, n" l' ?( wB.        程序因为第4行将出现一个运行错误- v' M7 U" B0 }  Q1 \/ H7 i
C.        程序因为第3行将出现一个编译错$ c# r8 ^0 b5 Q7 L
D.        程序输出”Equal"' v8 F" F% j4 y9 r* Z# o" o
E.        程序输出"Not Equal”) I: I% A5 W  Q+ |8 [9 y: w! n
3.        读程序:
* @7 z) _# e4 H- y! [1. public class StrEq{
# f5 `$ J) Y. p% _/ R) W6 l6 o2. private StrEq(){5 [4 P& T' D; x9 A
3. String s = "Bob";! i3 @) l* i& |* T% E, h, M2 d. @5 |" e
4. String s2 = new String("Bob");
$ T! j$ {* n, m. s5. if(s == s2){
) {' Y$ r; d+ k6. System.out.println("Equal");9 j% V1 D: ~! M4 j3 A3 q$ m3 L3 F
7. }' Y% N$ J8 g, x0 E5 e4 o) h
8. else{
* l; M3 H0 g5 [% x# f9. System.out.println("Not equal");0 {: U8 z& F! S: M$ w
10. }
$ K/ M0 \1 _9 n0 X! v11. }* i2 o. B8 P8 n% O
12. public static void main(String args[]){
. w+ ?, R. p2 \  G8 z# D$ |13. StrEq s = new StrEq();0 {- v" X  K/ T
14. }
# D+ U- T. r) O& h7 E15. }8 ~8 u/ i2 i. q4 b: {5 T6 U; F0 `
当编译和运行该类时,将会发生什么:9 p1 U2 t1 ~  r/ ~
A.        程序能够编译,并且输出“Equal”
" X+ u5 t& M: u; u1 W6 cB.        程序能够编译,并且输出“Not equal”/ j0 }) W* ~+ m# ?; ]2 t9 o
C.        程序因为第2行导致一个运行时错误
3 s' w1 Y6 G& P+ O9 w6 K" z5 [2 }D.        程序因为第2行导致一个编译错误
1 |" ?- j! T: n! }8 z8 d4.        以下那个赋值是非法的:% n* o* o' c! |
A.        long  test = 012;
0 ~( H. y  p2 K# cB.        float  b = -412;. J" \5 k+ ^" i+ Q
C.        int other = (int )true;' f- e" X  L0 I4 G1 m
D.        double d = 0x12345678;" a( L4 D4 s1 L; Q* V# k7 a
E.        short   s = 10;
; N4 }( N: ^. E6 c6 l5.        读程序:% ?* n6 X0 i; \) y. D9 W* ^" O2 H
1. class CompareString{# k4 o0 v. C1 C
2. public static void main(String[] args) {- V  |6 O5 v' s5 N! ]
3. Integer x = new Integer(5);. I6 X9 V/ d8 c1 A5 a$ Z
4. Integer y = new Integer(5);
5 n0 S7 `5 b8 i5. Integer z = x;
7 k& C. @+ V: f. B# o, n. M7 X0 c6. if ( ______ )/ D1 q' s3 T( P
7. System.out.println("true");
  U* o' n: }8 v0 ^8 c8. }
2 ~/ I/ O( j7 b( H3 t! U9. }6 X5 C  d7 K5 s% q0 X
以下哪个选项填入第6行后,不能输出true:
" }! j9 _" Q8 i$ |# ^. JA.        x==z
# q$ N! r- w: u+ ~0 p. YB.        x==y
4 i" j7 \0 n# X! h+ H* M: uC.        y.equals(z); R8 Y1 r! M# q# e$ M) {! L
D.        x.equals(y)
% s. |& B3 f9 {% m! a# D5 i6.        读程序(双选):( T# f9 M* R: d  m
1. public class Declare {9 w( T2 F  m1 X1 s% p
2.
& z+ l2 ~1 j$ i6 C% w3. public static void main(String [] args) {6 H2 \7 p8 z" S6 a. R
4.
: b, l* D& e) ]2 l! }' Q" O* \5. System.out.println("The variable is " + x);- w2 k8 e7 l' `. S! \7 y8 B
6. }
( Q' ~/ V1 N+ b4 Q7. }
% B6 \6 U8 G" l; c) J+ u1 k以下哪个选项中的代码可以使程序编译通过" H" H* F& Z7 U
A.        把“int x;”放在程序的第2行
4 m: s4 g$ q, h9 C4 `B.        把“int x;”放在程序的第4行+ a% E9 P7 i, Z! P
C.        把“int x=5;”放在程序的第2行
( {  l: K! q# ?7 a  e7 n' TD.        把“int x=5;”放在程序的第4行6 P# j- P5 Y: W* x4 I8 ]
E.        把“static int x;”放在程序的第2行3 }' z( m- `2 V! n: Y( }
" f0 ]3 b9 ~) B$ k- F. n
& l- |/ r2 j$ m% T
- O' Q6 M; L- d  H5 J& w. u
7.        读程序(双选):
7 ~7 ^. d# t: l9 v+ p6 L, U3 d! c1. public class Child extends Parent{
- Y% V" a$ c  S0 D2 h7 M2. int a, b, c;3 @8 r/ |, X& n5 N2 a, G
3. public Child(int x, int y) {9 J# t3 h3 g2 M  c* z
4. a = x; b = y;1 j: D0 w- |  K1 X* A/ A. i
5. }
0 W' V! X2 F0 `; C6 s$ B, Y6. public Child(int x) {
- d) ?9 ~7 n% H$ j6 ~7. super(x);, A+ g' n5 {* V: S4 R5 ^2 K( R
8. }& k) m5 ?2 L6 x' i, \5 ]; _
9. }( a+ Y: ^, U7 H$ b
为了能使该类编译通过,下面那个构建器必须出现在父类中:
2 r$ X; Q* U- s0 G( T* QA. public Parent(int m,int n)% l" h( ?+ I/ l; N2 ?) r
B.public Parent(int m)2 G* d6 l" j) l3 O
C.public Parent()
7 z8 b& W. G. N1 fD. public Parent(int m,int n, int o)+ S' G, r" O0 l9 V4 G, R
8.        读程序:
7 S4 t9 f0 u: Q  b0 @0 z; n' a% w1. public class Derive extends Base{  V8 g" s3 h4 o2 p
2. public static void main(String argv[]){: b: B7 I+ ?$ w& T8 X+ I( Q
3. Derive a = new Derive();# q! |& B$ S" Q( o6 j. h, P
4. a.method2();
; ]4 z% C# P' U* f5. }
! K- U2 F  V: x/ Q, l: t6. public void method1(){+ V: {, c7 J! B8 H
7. System.out.println("method 1");- ]% H' r5 M0 [  T: a! V: B! K. v
8. }
6 ?4 P5 e, u% l9. public void method2(){
) T$ Z9 U3 G2 i7 x' N10. method1(); + I8 \0 h" ]" d5 L
11. }
# ~, p; t8 k. @6 P0 p8 q12. }. m$ U4 x, P- u4 k& I+ Z
13. abstract class Base{: E3 r  P2 I) X" G$ X1 Y
14. abstract public void method1();- H4 e+ D( l1 K
15. public void method3(){
8 j- E1 j, v" k; B6 Y16. System.out.println("method 3");
! m8 o- f9 ^1 e& z0 v! F6 y17. }
9 \" X* a3 `4 H1 I* W% ]8 h}
- F+ @- B1 U, i当编译和运行该类时,将出现什么:/ @: J( l0 k7 w$ C/ c
A.        程序输出“method 1”
* D! [5 _# Z1 I: L8 wB.        程序输出“method 3”
9 Q9 s) r; s7 R  MC.        程序因为第15行而出现编译错误
: l; |$ `: `. w6 A1 o/ FD.        程序因为第15行而出现运行错误
% g  Q5 \. E8 U% ^  \9.        以下哪个接口的定义是合法的:
( P9 {2 a2 \2 U/ A; a# lA.        public interface A {int a();}
, |) a# X+ ^. lB.        public interface B implements A {}
- k# n; ~2 o6 |5 ^5 T% y  K) |. sC.        interface C {int a;}' v" {' U) x6 V5 |; z7 e+ A
D.        private interface D {}9 o0 A# O/ Z9 s3 L  k' L; Y
10.        读程序:
, g, g' @) }) C1. //File SuperClass.java
9 ^1 U+ [, R2 ~. q  q2. package MyPackage;
& K; m& K. e+ {$ Y  D8 ?3. class SuperClass{
. Y1 k5 B% T- H0 |; X9 E8 t4. void myMethod(){
, l1 ^2 V  d( G7 d* n6 G. P9 Y  O5. System.out.println("SuperClass");7 u; d- V. H  f$ Z2 q  f' W5 B
6. }
2 f" `, t* U+ b+ ^) ?7. }
, n) [! {3 T1 m% |( t5 h# R8. //File SubClass.java
" j& u! q/ |+ |9. public class SubClass extends SuperClass{
. T# h7 x: ]7 r6 p1 b% t5 m10. public static void main(String[] args) {
) D8 v: C! p: ^& \11. myMethod();
; S$ h; Y7 U, p6 W. T) I  Q" F' d12. }, k  c7 {( v' a! G- Q" |0 ~
13. }
) b3 `5 x/ t  h1 o当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:* F7 ~% Z( N$ C' z8 z% b+ Q* R; \
A.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”8 B+ l' y3 b& p$ U
B.        两个类都回出现编译时错误
1 t3 X  }! H% k8 f$ s# I! X/ [C.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误  M/ a1 y7 w2 D! V7 q* b
D.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误
8 o$ V( X7 f0 a+ d8 h11.        读程序:  y, T' d. ?5 P8 B7 r
1. public class Test{
6 J* X! Q" f0 c2. public static void main(String args[]){
3 e7 f# b: h- f3. int[] i = new int[5];% {/ O" F# T& p8 x  t1 `7 u, p
4. System.out.println(i[5]);' X6 ~& ^. c7 ~' f1 n
5. }. O, r$ s8 o1 w9 l
6. }
% f, Z" F, b0 I当编译和运行该类时,会:: Y% U2 B9 r- T' B# K1 f4 l
A.        出现编译时错误( d" e2 M* y& |1 j; w
B.        出现运行时错误
/ @9 D5 c+ X9 H1 r. pC.        输出02 ]0 W% z0 d0 n# y
D.        输出null
8 c" @/ m" @) |. ~( _) t) y12.        以下哪个选项是正确的数组声明或初始化:
! M" D  t3 R1 gA.        Array sizes = new Array(4);
+ Y+ c1 e# J8 {+ o1 c% e+ gB.        double [] sizes = {1, 2, 3, 4};
# R* h2 r4 F. O4 D: b# X( `1 ]C.        int [4] sizes;
% W8 t; R/ R9 |7 [D.        long sizes [] = new [4] long;
7 l( a. h3 ?9 Y- _6 ~- W13.        读程序:( i! {" m) r7 }
1. public class Initialize{' D. R% t+ `, G8 Q" z9 B
2. int x = 200;
* P9 w8 t8 G( A! d3. static {
, E0 r) o2 v; C! S2 v! v. i" P- v+ \4. int x = 100;' d: d# A  |- B5 ~7 V  ~' v7 g, N
5. }+ A% w2 z# ~$ s/ |' d
6. public static void main(String[] args){$ o" l" N3 ?+ }7 h2 e
7. Initialize init = new Initialize();' O$ x# O" M7 Q+ ]. I& J
8. System.out.println(init.x);, S$ ~( G* {7 D; H' c  A$ r
9. }6 n. r' z  e' ~1 t; c+ K" y  G/ l
10. }% p2 c# G+ o# |! e
当编译和运行该类时:9 l2 t- h$ i4 @1 a, F
A.        程序因为第3行产生一个编译错误
7 j3 K  H9 J! ~B.        程序因为第4行产生一个运行时错误
# [6 a+ \- W/ B5 yC.        程序输出100) L9 x0 o1 G( p# A! g
D.        程序输出200
( q! P9 K$ T! w8 x/ q0 C14.        读程序:
5 u. s, d" a0 O) ~8 p1. public int abcd( char x) {5 z+ d3 R2 t: A( [- j* s
2. if ( x <= 'M' ) {  ~7 A0 }1 v' F& g7 [
3. if ( x == 'D')
" V; C& _( R+ M  I# s4. return 2;
; ]; n/ Q0 B& ~) G5. return 1;% X6 P  e3 I9 h( q4 W1 v( `" D* r
6. }( ?6 L. y& u) x
7. else if( x == 'S') return 3;
4 T% U' y# D9 i: ]2 z( T- t& t8. else if( x == 'U') return 4;8 W- I1 ]* v# q+ g* I7 a1 w2 P  Q
9. return 0;) x( @1 @) I  N# ~5 |1 ~" o9 g% J
10. }
4 N7 R, |4 @' I8 m: x, R在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1! q  |1 w2 ~% J8 [
A.‘X’  a4 s/ j0 U# ?: O
B. ‘A’
- r7 `( w# h8 l/ K  j6 Y% e, L6 {C.‘D’: v9 U3 y3 |$ b) V( H5 c) i% C
D.‘Z’. _8 d: b# V) S7 g0 r7 d
15.        读程序:0 F# ^: ~2 v' O! Q: F
1. class TryTest {
) i" }; f% X3 j8 e4 l6 Z2. public static void main(String[] args) {. c: Q6 b5 q4 N* q
3. try{
# v3 F2 {, p- }& C* B( S7 b4 q4. System.exit(0);: \; R$ P5 S3 w  p. O6 f/ F; d) V+ c
5. }+ E+ M5 l1 i$ u. e- J
6. finally {
1 z4 @$ B7 v8 B" u# Q7. System.out.println("Finally");
6 @8 d8 e5 R: ^. t' L5 R. H3 `8. }
0 }% A6 {" I1 I4 A* ~" E2 L% o; |9. }
1 L2 d% v$ I9 u, F/ t* h) ]10. }
5 R4 e: R; c9 R$ j6 q  z. y2 ~/ B2 L- _当编译和运行该类时,将:
  \- [: d# A- |& ^A.程序因为第4行出现编译错误
; L" Y- D/ n1 T+ l3 u4 DB.程序因为第4行出现运行时错误; D% ?0 f/ _6 |. G+ h
C.程序因为第6行出现编译错误5 C( |$ w' c# `) t* n8 r+ W
D.程序因为第6行出现运行时错误, Q- o1 B5 q. m1 a: P. o) }
E.程序输出“Finally”) |  ]6 q* ?# L
F.程序可以运行,但什么也不打印
$ @. N2 z0 z; _) |4 _* M) W
1 @5 Z1 c' i+ Q7 |1 P) ^" v16.        Given the following variable declarations:
- @" ]2 v- I5 h8 ]$ kBoolean b1 = new Boolean(true);
0 ?9 t: s8 y  K- I* oBoolean b2 = new Boolean(true);* v( g% ~" U- {+ Z3 b
Which expression is a legal Java expression that returns true? : s7 ^" {6 o' N5 ]8 }. p
A.        b1==b2  \% V4 w7 M; t: ~3 ?1 U
B.        b1.equals(b2)7 C5 X/ s9 ^1 W6 t. y; d3 o' t& W
C.        b1&&b2
6 x5 F0 h9 R" C% g: vD.        b1||b2
9 S7 `; A, a' j9 X% p3 v& VE.        b1&b2
7 D3 [2 M* p' x& ]F.        b1|b2) a. d! F5 [. f  k8 N: b% r
17.        Given:
  X( I  e* i; L7 `1. public class Employee {
! E* d6 j4 d7 X- h* t& M) D+ w2. & _  G+ m* y4 r8 i$ v$ M
3. }/ e8 k+ F+ c7 A! x+ ?4 f
4.
& |* L) `+ T" U# w% r5. class Manager  extends Employee{
3 U/ }4 q) @7 Q5 W6. }* v. N' [% G4 e. l0 `
What is the relationship between Employee and the Manager?$ J6 O4 W6 B5 B% g; Z" ?7 V
A.        has a
8 K0 Q6 Q. [* r# OB.        is a
& E' P/ I8 k: H2 ?% D9 [C.        both has a and is a' O) B& k8 L, _4 M" N) `
D.        neither has a nor is a
5 m7 `+ y" ]- P" T5 S9 j) B18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?; }/ g/ H# `$ n
A.        BorderLayout
5 E2 N' Y" |+ IB.        FlowLayout
& [3 {' i& G7 m, T; p4 EC.        CardLayout
$ j. l3 ~% H  `/ R( w5 iD.        GridLayout7 D. T5 }4 F  W  B, o3 {; l
19.        Which of the following AWT components can generate an ActionEvent?: ~* w: l" a9 V0 T' j& F
A.        java.awt.Button
: r( G* P& y: Y5 k, Q' FB.        java.awt.Panel
" n2 W9 o, c5 K, dC.        java.awt.Canvas
5 `' q4 v* I( W3 i1 G0 ^6 T4 [D.        java.awt.Scrollbar* |) h' `- w0 U
20.        What kind of Stream is the System.out object?/ @# D: C2 c0 j' ^
A.        java.io.PrintStream1 r+ l6 I0 i7 z, \% F
B.        java.io.TerminalStream
, O# W. b$ y' E6 K/ HC.        java.io.FileWriter
* Y$ V2 J# c; Y3 f' l. r+ O) M9 C' hD.        java.io.FileWriter& r  v: W' v% h
21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)( \7 j% i9 C; l- j; ~+ R+ o
A.        java.awt.event.FocusEvent
4 a" Y6 V/ Q9 q$ q: V1 q: V9 gB.        java.awt.event.KeyEvent) _0 U5 t" L! m9 B9 j
C.        java.awt.event.ItemEvent; |" q- W% y2 J0 @# v" l
D.        java.awt.event.ActionEvent
7 Q: {6 B% h$ S22.        Which of the following methods are static methods of the Thread class?(双选). ^: |  C. j. n  Z3 k: d' Q
A.        sleep(ling time). N7 |5 o8 M1 d5 `9 ?9 S6 }
B.        yield()3 ?/ m* l. p  L6 |- e
C.        wait()
. d/ N, v8 Q. U; J" aD.        notify()% E  D6 r4 k( \$ f/ [2 y6 i
23.        Which method do you have to define if you implement the Runnable interface?
9 K8 w9 o# h5 YA.        run()
: z' R( G' U7 N/ @' YB.        runnable()
1 G* t, K. K  a+ [C.        start()
0 _5 l* w( z, P; y2 {D.        init()
7 a3 F7 X& B2 e) SE.        main()5 Z) [$ k: |5 J! x) S
24.        Given:* A+ @% Z9 k6 z
1. class MyThread extends Thread {
; r( i" h7 {& K. T8 z2.
/ @- ?/ s# R0 ^! R; n; c+ A. \3. public static void main(String [] args) {
$ C6 h% P( l; M- e" e3 ~+ H4. MyThread t = new MyThread();/ V" d1 a1 N/ z: c0 l  A5 q% W4 l4 ]
5. t.run();6 f9 f9 _' p; i9 w% n/ B
6. }. ^9 K5 T! l4 U% W3 m1 Q! S/ T* a
7.
: d% [. y; Z$ D& X8. public void run() {
' a1 ^7 F% S( |) M- c9. for(int i=1 ; i<3 ; ++i) {
8 N( j: _3 C' F' d/ ]10. System.out.print(i + "..");
6 u( k6 r% v/ m11. }
( S: o5 g2 }/ _: d- n+ K+ ~12. }
: G7 ?; [) S. ]13. }
- M/ q; [5 @4 v9 s8 f' y7 RWhat is the result of this code?C
$ ]  G% d. I# w3 uA.        This code will not compile due to line 4
8 A' l/ w. `5 c4 u2 t. B, G6 }% vB.        This code will not compile due to line 5
( ^& H! m6 Z: j( P* f" UC.        1..2..; v: c( u) y& e
D.        1..2..3..: q, F* ^6 e. a7 a6 u
25.        Given a local inner class defined inside a method code block, which of the following statements is correct?( H) S, L- ]' I2 G) W
A.        Any variables declared locally within the method can be accessed by the inner class" `: v( O/ m  [5 e9 ^
B.        Only static variables in the enclosing class can be accessed by the inner class  ~1 g/ N: W* {5 U/ X4 \$ O
C.        Only local variables declared final can be accessed by the inner class
- f6 |2 V+ E! Q5 F3 j; qD.        Only static variables declared locally can be accessed by the inner class., {) ^& c3 F8 K
/ i: f0 Y  u& S5 n' h

  U. e+ z" ?- {. z- k  y  ]! I, a. C7 h! V
26.public class SychTest{
( `4 g! V+ C0 w0 @! Y   private int x; 3 B) U5 L( H! x$ ~9 v6 v
   private int y;
, A" m8 U- M: c' F   public void setX(int i){ x=i;} * u: B3 V$ D* s6 C  p5 c+ `0 k
   public void setY(int i){y=i;} $ X- w, |* e# H% ?6 Z" H
   public Synchronized void setXY(int i){   e. K! S3 h; ~; P+ z# a
     setX(i);
; t" d- h. |( n, f* f# |     setY(i);
! f0 v. _/ u7 f( E: ~3 @" Q   } 3 b6 E4 v* V# l3 Y
   public Synchronized boolean check(){ 9 p) ~7 Q. q/ g0 H8 O
        return x!=y;   7 O6 v, F' g( t
   }   U1 ?/ ~, `1 K6 s1 f6 W
   }
$ d" T+ ^$ m: O4 L, N" G0 V% K    Under which conditions will  check() return true when called from a different class? ! N8 j# A$ d1 M* D& F
   A.check() can never return true. ! ^# J0 F0 Z/ o4 C. y/ J
   B.check() can return true when setXY is callled by multiple threads. 8 {# V7 R* v* P9 J" Y
   C.check() can return true when multiple threads call setX and setY separately.
6 ~3 K8 A3 @# O) b   D.check() can only return true if SychTest is changed allow x and y to be set separately.
( W  j) x$ R. e2 S7 u" G" d$ W9 u# M" Z) d; M- {5 r9 _
27. 1)public class X implements Runnable{
: j1 i/ q: c0 u5 j* p# x7 O  2)private int x; 3 n8 p% ^+ Y" }, q) u
  3)private int y;
0 g+ _7 g) _9 N0 q  4)public static void main(String[] args){ 6 M/ ^' Q/ A8 i% }5 e# ^( U- h4 o
  5)   X that =new X(); $ D( h- p* l% u- T; a
  6) (new Thread(that)).start();   |. d; h! S! `9 g1 \% |9 `
  7) (new Thread(that)).start(); 1 i+ Q$ k, U/ d4 P) R, ^
   } . z6 I; ~4 O3 q( @; h2 w, w
  9) public synchronized void run(){
" T& f1 {4 ^' i/ L$ P, W( h+ W+ r* Q  10)  for(;;){ $ s' A  P$ X% w' a- e# V
  11)      x++;
; }4 b2 f. j! @' {, k  12)      Y++; 4 Z8 m1 c7 w  l& p1 L. y
  13) System.out.println("x="+x+",y="+y); + k9 ?- s' W) H5 J
  14)    } ( h" P* K5 a+ O! Z( `7 x5 {
  15)   }
, n2 t' C2 ?* g1 i  16)  }   - c" Q( x- f# W
    what is the result? & V# K+ a) p, W9 d6 j7 r
  A.compile error at line 6
& n8 i/ P( @9 y, D. d  B.the program prints pairs of values for x and y that are # T' m' X1 F/ j
    always the same on the same time : u' g0 X  g" R; |) y0 ]

6 _: g( n7 q* p0 W28.class A implements Runnable{ " _5 b  b7 g2 c; X7 N
  int i; 4 x/ f* P0 ^" ]; |) {% l; _0 ^
  public void run(){
( a' d- z" C! P4 L% q7 ?   try{ 1 D* X5 Y) x' l7 H; B6 B5 P
       Thread.sleep(5000); 6 x9 S/ ]+ }! }# R. ^$ ]
        i=10;
" j+ A+ f+ t  E6 i       }catch(InterruptException e){}
7 @5 \/ S1 g9 V, C, y       }
* w8 I7 R2 r3 u. {3 B$ R2 x5 E       } + H0 x" r% [& m8 }6 P
   public static void main(String[] args){
5 I7 k/ e% k2 l# H2 T( a      try{ ; W& I* d7 j( q+ A3 g
         A a=new A();
( a9 b, \; B7 O4 U  G* S8 ~& X         Thread t=new Thread(a);
. M. U& T  f! W" I0 l  O5 \- Y         t.start();
+ T) c8 c9 o; N# N! y( @  17)
7 E2 u% Y5 y' B5 G: `7 H  I      int j=a.i;
8 N( n, h6 Y5 U; b" p& }  19)
0 i" b. X) P4 E7 d, M  o      }catch(Exception e){}
2 i$ F/ D* |; q( p% y      }
0 t& t, l* |  c& [      } * D' e' ]9 z& F$ c# C3 O
  what be added at line line 17, ensure j=10 at line 19?
( C( W9 Z# b& o2 ]: K4 z  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   9 z, {6 i6 B1 I7 J6 m
  E.t.notify();  F.  a.notify(); G.t.interrupt(); ! ^/ ^# _- W4 R( q& M
29.1)public class X{
" P9 S: u& {5 N- {3 B: c  2)    public static void main(String[] args){ 6 m- n; l; C# ^. {0 z0 R% v
  3)     String foo="ABCDE"; ' H' J8 l, t* W: Y+ X* F3 y
  4)     foo.substring(3); 5 C4 Z. B$ c( B# o- ~  A
  5)     foo.concat("XYZ"); , x6 I; D; l% S) i( A# Z: }% o
  6)    } ! N, e4 G, V0 f* @/ r: r
  7)   } % J2 p) L1 ~' v$ M1 z0 ^) e
  what is the value of foo at line 6?
) b  r4 D2 {! X2 t5 d30.  public class Test{
; t' Q$ S$ t: L9 G   public static void main(String[] args){   h/ _  ~# n3 E
   StringBuffer a=new StringBuffer("A");
$ u( T: T8 w$ z" j   StringBuffer b=new StringBuffer("B"); 1 ~7 S" N6 z4 p3 o. r9 @
   operate(a,b); ; g/ e0 h9 }) v' F
   System.out.pintln(a+","+b); 3 z- |7 M0 P% u& H0 R
    }
; [! J( |5 D5 N# J" m$ A9 R7 [   public static void operate(StringBuffer x, StringBuffer y){ % \* K+ U' S* C4 O- J( q
    x.append(y); & d$ L; Q+ N( J" N& f  ^  w/ c( x
    y=x;
5 n7 L7 i$ a3 h0 _   } , m3 F1 }( i7 D3 d
   } 9 z  o/ u  u( {0 d
   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享
8 O  ~' O1 Y7 j2 v) B- j4 R我已下载。。。。。
# ?4 T2 g0 Z' z$ a特感谢您的大公无私
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-8-20 22:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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