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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题" V6 H# s7 I, s) ^: u
1.        给出以下程序:
  ~$ x& X" C5 }" \, b5 A& G1. public class Colors {" t5 J! R0 D  v! M; A, P
2. public static void main(String args[]) {. ~5 ?- X/ c1 g; _
3. int n = 1;
% T* g8 H+ d2 I! R+ j7 h. D+ S4. System.out.println("The Color is " + args[n]);; m3 o# c" K9 V
5. }
+ a! P2 Q: U  c% v3 x$ d  h6. }
, J6 b" h2 {! B4 p5 L假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
# Z0 k5 E+ V5 {* |$ z- L# a) U* pA.        Colors red green blue yellow6 h! E" i. \, E9 A. \( s
B.        java Colors blue green red yellow# _# [7 E6 c. G: h/ i
C.        java Colors green blue red yellow
4 N: x8 ?# e+ A% oD.        java Colors.class blue green red yellow( b6 E; V! R5 p2 A2 Z5 R# M& a  S" C
E.        java Colors.class green blue red yellow
( c2 |3 ?0 `' t* l$ ]7 K. d2.        读程序:- Y8 h- h  @$ v' g' i+ u
1. public class Test{
, `* Q6 G* ]) J" c  F9 f" B2 f2. public static void main(String args[]){
+ b4 F! a/ j: f# `1 v) @+ p: y# T3. char c = '\u0009';8 ^1 |  j. w7 v5 f, Z; h& ?( H
4. if( c == 0x0009L)! c/ g5 m4 l% F
5. System.out.println("Equal");
- ]2 T6 ^0 g8 O6. else System.out.println("Not Equal");  Y: L7 D/ c0 N  b3 }8 ?
7. }
0 l+ g- l9 e0 y2 P2 d2 Z8. }
0 E' j/ f0 b( V当编译和运行该类时,将会发生什么:
% z6 C4 h4 v  S4 P  L8 YA.        程序因为第4行将出现一个编译错误5 y6 V4 F/ f4 ^
B.        程序因为第4行将出现一个运行错误
* O9 T; c* H# W+ XC.        程序因为第3行将出现一个编译错6 a! b. i' Q/ Y, [- K
D.        程序输出”Equal"
$ r6 o) ~3 u7 I- i' E1 xE.        程序输出"Not Equal”* g9 s$ C/ ?! [, ]1 C) O/ }
3.        读程序:2 x* {/ d" g2 v" m
1. public class StrEq{% }! X: v: o! P, Q& l
2. private StrEq(){3 o9 o  V! k' `; i+ E- q/ A
3. String s = "Bob";# ~# X( h: g2 z
4. String s2 = new String("Bob");
& x3 L7 }- R% q5. if(s == s2){
5 I& C+ f9 J" t, J$ K6. System.out.println("Equal");
& s) \6 [( z& Q) @6 O7. }
! e2 k+ _8 [, ]: c3 j+ q8. else{
, b" i% A$ n6 D! u, n0 ~, B9. System.out.println("Not equal");7 M% a, j; M0 y# Q! ?0 q: W  _
10. }' C/ I- ?& L+ n) y, O  K
11. }$ \  l- D; B' W6 m  G; O( L' g
12. public static void main(String args[]){, v7 g6 Q, {( r) Q
13. StrEq s = new StrEq();$ C  i8 ?  P- e: ]4 f
14. }, [/ @8 H8 M. S' @" G" O
15. }% W: i) d2 _3 X, s2 a% k
当编译和运行该类时,将会发生什么:6 E9 N! H- X  ~+ f
A.        程序能够编译,并且输出“Equal”
8 Q0 m! Q. V- ]* z. }; d' @B.        程序能够编译,并且输出“Not equal”+ x4 u9 b, l% Z: h) C
C.        程序因为第2行导致一个运行时错误
8 F5 g7 X9 ]6 K2 t4 uD.        程序因为第2行导致一个编译错误
7 t' L. v- j6 t+ h) N3 a4.        以下那个赋值是非法的:1 P% ~( p' L, u6 r
A.        long  test = 012;
; \6 ^2 S+ A! O3 R$ `B.        float  b = -412;. L9 ^# i# @  h9 s4 p
C.        int other = (int )true;/ C( z, C4 f4 v* |
D.        double d = 0x12345678;
5 e2 ]7 G& o( ^E.        short   s = 10;- \7 D: X4 O# Y1 B) c; R" g0 r5 x
5.        读程序:
1 h& s3 u  `! r8 Z0 H  w6 M1. class CompareString{
' L* b( q, Z+ f( H& [9 c! ]2. public static void main(String[] args) {
" T6 b: m# x+ S, x% B. @" u0 ]2 F3. Integer x = new Integer(5);
& @: g; i4 o" c4. Integer y = new Integer(5);' _+ }+ N# i  a% d
5. Integer z = x;- P. B( \: W1 _
6. if ( ______ )
, G3 i% o0 P6 B* X& a2 X7. System.out.println("true");
4 T7 p/ W0 p/ c! y3 Z8. }$ k7 w& K  N0 Y1 h7 j& i( v
9. }: E1 i  L* l; S5 m* A- b; r
以下哪个选项填入第6行后,不能输出true:) U3 T) g$ O# r* d6 Z4 C
A.        x==z% n4 k% P/ T4 w. C+ K
B.        x==y  ]. F9 |5 r4 R& C% }
C.        y.equals(z)
# n" Y- Z( |! c: k& eD.        x.equals(y)0 j0 p5 M( H5 J/ F6 D5 _/ B! U% D
6.        读程序(双选):
/ x2 Q1 A7 s/ y& H) [( H3 i1. public class Declare {: i% Q2 [7 d1 W) S
2.
* G7 _) k! v) y* P3. public static void main(String [] args) {/ C! P- m/ w3 I% |
4.
7 v7 }6 b, ]: G) u- z5. System.out.println("The variable is " + x);
( }+ e' [+ Y: o4 |$ f! `6. }  N6 X: [! U# Q, d( J1 }. T
7. }+ f' I% T: W3 ]* a2 l
以下哪个选项中的代码可以使程序编译通过" G( {* L/ J" ]: @% Z
A.        把“int x;”放在程序的第2行
5 [$ n- h8 R9 m5 [B.        把“int x;”放在程序的第4行
1 S% o5 ~" j' w3 Z5 g; g. DC.        把“int x=5;”放在程序的第2行( P. k! n- ~' \  }3 V1 e
D.        把“int x=5;”放在程序的第4行% |" j2 E* J5 A9 \
E.        把“static int x;”放在程序的第2行! c0 t) L9 Z7 |9 a
  D) [0 y4 H, i; x8 B4 F" r
7 ]7 [3 O# W# o0 K% M, O' f& [9 I+ S

! G$ R* A+ a" n1 L9 E# a7.        读程序(双选):3 X# {: r" Z4 [. k
1. public class Child extends Parent{% t- F$ ]: E" H" t
2. int a, b, c;
. V: R/ \, G- s; |3 L3. public Child(int x, int y) {
5 Z, ?: _# x4 X7 m; ]4. a = x; b = y;
9 G  j6 [8 b) M% q. g  @& X5. }. h8 b: W6 w- t2 H- Q
6. public Child(int x) {
& R3 k( I1 d/ ?& c; t/ l7. super(x);
- B- a- [# J9 r: ]5 P. s8. }6 Q6 T2 [5 r' }9 C, r% n! b; e4 T
9. }7 N0 a' T5 P! @; D: i
为了能使该类编译通过,下面那个构建器必须出现在父类中:
7 [. O% D& u) X/ `; o$ c! y) o8 d6 ^A. public Parent(int m,int n): a$ L; x( e' X. Q0 @- }1 u
B.public Parent(int m)
" U9 V; O+ k9 \% B4 ~C.public Parent()9 \5 Y9 k- m1 y2 g' T
D. public Parent(int m,int n, int o)  ^' ]7 V% f9 T9 `" V! e( P
8.        读程序:
! g6 C  M" a; s1. public class Derive extends Base{
' H0 j* k1 X, N4 \: `( z! G. g2. public static void main(String argv[]){
. N7 d& P! K' v( D0 z3. Derive a = new Derive();5 Q: N( e" c& h9 R
4. a.method2();2 x  \5 h( X  a: `& C  O! K
5. }; Y) _7 O3 \: @, q" P
6. public void method1(){2 h% B$ G0 v3 ~# E4 r7 T9 r+ R1 c0 x
7. System.out.println("method 1");) M% ~4 }4 V" P; W9 o3 j# s6 T
8. } ; E- U* Z' V+ O, `/ M  M
9. public void method2(){
2 H8 M7 w9 d9 e% r$ D" g% ^! ^/ p10. method1();
. P  v) n  J" J8 y% p& u11. }
& e' }2 D" o$ X0 Y12. }
  \% A$ t% c; b. O& |- A7 C13. abstract class Base{) c$ L) K9 r# w% a1 Q- v) @; v' n
14. abstract public void method1();/ U2 H7 E9 J9 K; C$ W
15. public void method3(){0 m% @' @! E5 Y4 a/ x3 ~
16. System.out.println("method 3");
7 }/ p: p" R. V: f& o17. }" t) N( g; R9 G* T2 g# q+ n
}
6 \0 m5 s7 I5 x( Q当编译和运行该类时,将出现什么:
1 o4 h  ^9 v! xA.        程序输出“method 1”
0 T, u$ m, X" ?/ h" `+ @2 ]B.        程序输出“method 3”4 c6 a* k8 Y1 e2 U( c. L/ T) ^  V" {
C.        程序因为第15行而出现编译错误( T" I: \" z8 `: E+ U) v0 c
D.        程序因为第15行而出现运行错误) c2 n7 m/ v, `* h7 T
9.        以下哪个接口的定义是合法的:! N' `( T+ Y* `' d
A.        public interface A {int a();}
4 c# ~5 x9 w- O, {7 T7 E9 e5 }! X) L" kB.        public interface B implements A {}. m, Z7 u. l" w/ j
C.        interface C {int a;}5 n1 V5 X) _8 C' |! d
D.        private interface D {}% b' S- c) K3 v0 @  T' w$ C4 k
10.        读程序:, x- r  L- P. o# f7 L# ?
1. //File SuperClass.java
/ L$ n2 E' S3 u5 W2. package MyPackage;
, e# O0 ~# b7 D5 _' ^5 |3. class SuperClass{+ V7 w: C& R9 C* N  d
4. void myMethod(){2 |+ q# Q4 \" G
5. System.out.println("SuperClass");; H4 ], Q. s0 f& l( T
6. }
3 F* G! B1 v$ p( U1 L7. }
1 T& X' Z* F. P. C7 j, l8. //File SubClass.java
8 K2 l6 \3 v  \) v! f2 S+ Y7 x" S9. public class SubClass extends SuperClass{
. Z. n: e2 ]/ D10. public static void main(String[] args) {
" J$ g0 x2 ]" G" f. M11. myMethod();
* u4 h6 B  W. F! C2 t% Z12. }
7 i6 G0 c0 C6 j1 l8 ?) z6 F9 }13. }
) n* H: `# g0 R当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
, E. A. R3 H% v' _, M& FA.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
# Z* e7 J, w2 J* s, O6 z, FB.        两个类都回出现编译时错误
8 j; {3 C' \: y6 ]  E* u, g, qC.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误
# M! K$ o( j" v( \- l. RD.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误+ M1 O4 E) V" N% x  T8 c
11.        读程序:/ ^* R- o7 p/ _/ q" k# }0 K1 q- ~
1. public class Test{
$ J' x! W; b9 W3 p% Q& J2. public static void main(String args[]){
; e, ^4 K8 H# _3 z% s! U* }3. int[] i = new int[5];1 _3 w0 v5 s( v9 q- i6 |
4. System.out.println(i[5]);
6 c# V, Z* C* t% l' c5. }! J6 g* c$ m* O1 t- S' I1 E
6. }* S% X3 [+ m- }/ ~& G; E! f
当编译和运行该类时,会:8 j# C8 F7 K. V$ d9 `& u/ g
A.        出现编译时错误7 H  L% {) ?. E7 ]6 _
B.        出现运行时错误
5 K( {! c7 Z- o" E9 m( t, }0 o. ]C.        输出0
* G0 z# y+ H, KD.        输出null
, D2 ?1 p4 H1 }" J6 h0 u. o' W" ?12.        以下哪个选项是正确的数组声明或初始化:
3 l/ h2 \+ A# l" a8 ^/ f& p9 zA.        Array sizes = new Array(4);! a% V: D6 W7 R
B.        double [] sizes = {1, 2, 3, 4};
9 Q, d( M- k/ s, [C.        int [4] sizes;
* {% O6 H0 v2 O  w* q6 C4 ^$ ?' ~4 Q/ OD.        long sizes [] = new [4] long;/ F$ S9 B+ S: z: a9 j, z
13.        读程序:
4 l( ]8 x9 w5 [0 h- {1 g' W1. public class Initialize{4 _2 m) I$ |" K# G
2. int x = 200;! T  G0 ?! a! |) Z9 m: g
3. static {
* }5 \  b( p) U% t5 t8 G0 i- O4. int x = 100;( J  N, ^' w9 N
5. }
. j+ H) P& H" d. N7 t) t: \: F6. public static void main(String[] args){' y1 A% e& @" F* Y
7. Initialize init = new Initialize();4 _  q$ m: X+ j
8. System.out.println(init.x);" g7 y% w( B) V- S: A; T
9. }
( a( p( l0 `9 l2 ^7 ]5 K6 }10. }8 Q2 [5 f3 h: f6 D" m
当编译和运行该类时:& G# ~( ^# F; \; }
A.        程序因为第3行产生一个编译错误
( S$ b3 \* q" `+ s0 l! AB.        程序因为第4行产生一个运行时错误
7 r: ?" T" n/ r+ F1 e. BC.        程序输出100
3 n* j; J% y. @' DD.        程序输出200
* Q5 N7 y' ]$ @14.        读程序:
+ Y( l0 |- V% e! Q+ z1. public int abcd( char x) {
; S* \9 n3 \, m2. if ( x <= 'M' ) {( G; i9 ~+ L( Y, o5 l
3. if ( x == 'D')
& t4 @& _9 E+ s7 X4. return 2;8 O- G1 T( _+ i3 \# p3 l! e
5. return 1;
8 V& Z/ v, Q/ X  d& j1 d& M6. }
. K* Q7 [# x5 O1 E8 r  d1 E* c7. else if( x == 'S') return 3;
6 A" \6 Y/ ]6 M5 s( s' F8. else if( x == 'U') return 4;
7 e" {0 F; P& H  h' Y, P  L9. return 0;; ]" a6 ]6 A  {" _5 q& C: }/ I
10. }0 a8 j  x  ]: Y: M
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
3 [7 S% ]9 P6 e; _, oA.‘X’
- P  W4 y+ {8 A8 g: MB. ‘A’
8 |3 @3 x0 {6 ]' r- HC.‘D’
2 [. _8 L5 ?; P2 S2 C% p$ VD.‘Z’
1 B1 _: Z& d; {3 d( o15.        读程序:
% Y4 Y% d: H. s, V! K" @' ^# R1. class TryTest {
3 E1 H7 P$ ~9 J2 q2. public static void main(String[] args) {
, D- M5 d0 K0 z2 B3. try{
' f9 K% b5 B$ V& x! O) O8 R4. System.exit(0);& e( s( k$ W: c: K- F4 H6 @  v  z
5. }. u: s) [' N+ x
6. finally {6 {! W9 w6 D; C: |$ M, `0 f
7. System.out.println("Finally");
8 s6 W* |( A" T1 ?8. }
3 h) w' }) f6 p' z: q" ^9. }# k- C  [( k" M) `: |3 v
10. }
7 i& u$ N! a: k; S" s当编译和运行该类时,将:% }  }+ A9 F9 ~( [7 l
A.程序因为第4行出现编译错误
7 y0 O& q! S" D, ~# K, j9 LB.程序因为第4行出现运行时错误6 h6 y) s# I$ T  S
C.程序因为第6行出现编译错误
+ G, @" G4 M# J+ ^2 e' sD.程序因为第6行出现运行时错误
' a6 D3 g, b8 E" O- _E.程序输出“Finally”, Z; H% M7 c& E  C9 I1 b' [
F.程序可以运行,但什么也不打印' ?  x- R2 M; F; }

8 L0 Q, @7 J2 z; e, k1 R16.        Given the following variable declarations:5 t  ]! o5 n: r2 {
Boolean b1 = new Boolean(true);' m+ b9 R  ^: ?
Boolean b2 = new Boolean(true);
8 F9 s+ |  X* B' ?) M* _, {# TWhich expression is a legal Java expression that returns true?
/ d- g. g$ O0 M, d8 `' G$ VA.        b1==b2
+ W; B4 P( |$ `4 N2 D: m- yB.        b1.equals(b2)
1 W% D8 u9 a: C/ L/ ]- A3 \* DC.        b1&&b2) \) H; n. B) R
D.        b1||b2
6 A! {9 Z, ?# e' q- IE.        b1&b2* G) O8 o) I! v7 b( z! ^  ~" E0 `
F.        b1|b2* l  @; J4 d! j6 h; r6 }- f
17.        Given:
7 S" F1 c0 l3 Z" [' d8 g1. public class Employee {8 f& ~4 b9 l8 _4 I7 o  ?
2.
8 @- L, Y' ]- Q5 b7 ]3. }
$ a$ O& p# ~0 z0 z' V4. 3 Z* E2 }; y' l! X3 `; |! J
5. class Manager  extends Employee{
6 l% D! }) _! q1 A$ [1 x6. }
+ M. Q3 b2 g9 W2 DWhat is the relationship between Employee and the Manager?
' V5 Y6 I' \  I/ B: g: LA.        has a
! P" P& w; o, w) HB.        is a
9 A& H( R/ Z6 B8 _; `8 g2 z: P3 T% SC.        both has a and is a, ?/ c; @- O. i
D.        neither has a nor is a
3 v* ?  ?: ~! n" P18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?' s* }3 q  u" b$ i9 M+ w7 c
A.        BorderLayout6 D* J  m0 R+ b& M/ p  J
B.        FlowLayout
0 f. X0 r! m* C4 C& ]C.        CardLayout' x8 _1 l/ `$ S3 u- Q
D.        GridLayout* I3 I& L. n0 a$ X& y
19.        Which of the following AWT components can generate an ActionEvent?
9 E; H/ K2 J- l2 UA.        java.awt.Button( ]. W" s/ y- b0 Z: }) i) U# R; I
B.        java.awt.Panel8 x& X$ k+ {) n5 ~  R4 G" z
C.        java.awt.Canvas' C- ^( a  \; y" }. v1 i
D.        java.awt.Scrollbar
" `- R5 `' d" {1 E  {20.        What kind of Stream is the System.out object?
% J/ L4 j& Q6 `" }+ sA.        java.io.PrintStream
9 ~7 L4 s2 l* yB.        java.io.TerminalStream; c" c' U" R7 T3 p% x. ]9 {
C.        java.io.FileWriter0 A- g% Z# t1 x0 a( l
D.        java.io.FileWriter
& c( ^) z( g! l$ T  s21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)
5 q. Q# a$ ?! B* e1 WA.        java.awt.event.FocusEvent* O! K$ q& V- Q
B.        java.awt.event.KeyEvent
6 Z5 b  j+ N7 R3 xC.        java.awt.event.ItemEvent0 L2 ^, n- [  M: E
D.        java.awt.event.ActionEvent) f& k$ j! Q3 q$ Y; g' X" q; e
22.        Which of the following methods are static methods of the Thread class?(双选)$ p3 ^0 f6 ~% f8 W* B
A.        sleep(ling time)
6 ]0 h& ^: P' I- @5 ?9 }: AB.        yield()
& j7 {3 I: k9 T/ d5 C. U/ |7 o, ]C.        wait()4 |* f2 ?$ D/ g' G7 v1 K
D.        notify()
% o$ p! W8 d7 ?) o, W23.        Which method do you have to define if you implement the Runnable interface?2 r/ |1 p. e" p1 x" m0 ]! e
A.        run()
4 p- ?. c- y! @4 |  ZB.        runnable()
6 O1 q9 T  {* S4 c+ J8 eC.        start()) V6 Q" d, u0 j% ^9 F
D.        init()3 U" r  T9 x5 Z9 n4 y* \
E.        main(): e1 P: }7 f6 t  `" f. q7 O/ F8 D
24.        Given:
1 q* Q7 A' D  K6 S/ F. \1 o2 K, A1. class MyThread extends Thread {
/ o% w2 i9 A3 m* r7 N7 y2.
- M* _9 @0 i! e2 y( r- C3. public static void main(String [] args) {' ^- ~' H# X% _6 j4 l" K1 Z5 r- f
4. MyThread t = new MyThread();
% s% h! b6 ^( |5. t.run();
- I/ I: |3 w9 ?2 Z9 B6. }: s( [/ E" e8 G' A  c& ]
7.
0 {" O9 b. c- _! q( T7 y1 U8 K8. public void run() {
# B6 ^* u/ `) M. l9. for(int i=1 ; i<3 ; ++i) {1 B8 d  W9 m# t! u! j0 ^' P
10. System.out.print(i + "..");
3 N4 _  w% t7 Q* `5 P( V. o: ^9 L11. }! [6 _7 h, V; y
12. }4 `$ j& d7 W2 C& O2 E" I
13. }
0 [2 M. B$ P, @What is the result of this code?C
/ r. M8 s+ y# TA.        This code will not compile due to line 4& N1 A7 d& T5 d: X; ^1 N
B.        This code will not compile due to line 5
  u. X. Q, ~0 M9 @" i1 r' wC.        1..2..
& o8 b  J; u/ J. cD.        1..2..3..
8 |6 ?  W- h* F( `# M% d  e* c4 K25.        Given a local inner class defined inside a method code block, which of the following statements is correct?2 K8 i) v3 r, Y$ b% _# e
A.        Any variables declared locally within the method can be accessed by the inner class
+ B7 E% H+ Y; _1 L! B  cB.        Only static variables in the enclosing class can be accessed by the inner class4 ?% n. O$ |  G' A( X3 q6 n- D
C.        Only local variables declared final can be accessed by the inner class8 F; b8 X3 e% ~
D.        Only static variables declared locally can be accessed by the inner class.
! ]$ x% X8 ^3 c; z7 O4 [
" }* N5 W" B0 J& {+ h! I% i
) s. d( v' X( B" g3 m- ?0 J( G8 a1 U* n2 q  I- P! F7 N
26.public class SychTest{
' M7 {$ \1 _( G9 [$ x, E   private int x; ( v2 `% w2 q- W, o+ d; a/ J
   private int y; " T" n1 N7 g2 ~: e2 t
   public void setX(int i){ x=i;}
% Y" l9 t- m0 H8 _; O   public void setY(int i){y=i;} ! G7 |4 m$ T. G9 O5 \
   public Synchronized void setXY(int i){
1 @' v. Y1 {5 \$ E; a4 W+ \     setX(i); 4 @0 a7 W8 x# y  h! _9 ?% M/ d+ f
     setY(i);
+ f6 I, U" u' u/ [6 v   }
! i$ F3 n+ a3 z% K4 Y   public Synchronized boolean check(){ . c! ?, e1 Q, U; A4 G0 w  m
        return x!=y;   2 v  `( E- M6 y8 I5 z; L7 |
   }
4 H  V! K4 J6 u; }   }
! E; n% V$ b$ k    Under which conditions will  check() return true when called from a different class? # Y  ^2 [2 I  x8 j- ^
   A.check() can never return true. ; s1 S1 l& U4 y, t  Z
   B.check() can return true when setXY is callled by multiple threads.   a. a! `+ ?+ X& A
   C.check() can return true when multiple threads call setX and setY separately. 6 @! {  K. m+ A8 \7 R
   D.check() can only return true if SychTest is changed allow x and y to be set separately. 4 m$ Z! v% W; t. u4 o

  L) Y, I' B7 b2 X7 H9 u27. 1)public class X implements Runnable{ & o5 u+ _' J) T$ |. s9 u
  2)private int x;
3 L' G* N. T8 H' O; m  3)private int y;
, Y: m+ i: `2 W7 H" ~! m- m6 b  4)public static void main(String[] args){ # h! G6 k9 N: x" N" l
  5)   X that =new X();
- y% R% G$ @% k3 J  6) (new Thread(that)).start();
& O8 o; r' w- k! g) u2 g  7) (new Thread(that)).start(); , a3 o) O; @5 R/ g5 F1 I  k
   } . w( w& d: M+ c" C! q( S
  9) public synchronized void run(){
! |6 [1 m7 b% T% p' ~  10)  for(;;){ 0 d# r' ]7 I1 l6 I/ T! K! H
  11)      x++; ) P# y9 c/ {* P& y0 ?3 ?9 A. n
  12)      Y++;
# m" {7 o' r7 g/ ~; O  13) System.out.println("x="+x+",y="+y);
& M1 p9 C  O0 g! p, O  14)    }
2 A' G2 _. p/ N, y# {0 K9 @# }  15)   }
7 [: M% K; X6 u3 X  q$ j0 C  16)  }   ' c" }  A$ F0 V) b. I' j8 X; J
    what is the result? 9 A0 o! W, x& A2 y( d
  A.compile error at line 6 6 @' g( l' J; V/ o& Q
  B.the program prints pairs of values for x and y that are ( j; ?* `) N4 K- F
    always the same on the same time
3 [7 I% l" {3 c9 o' M% [5 Y8 k( k+ h' Y: ~0 D* M3 {
28.class A implements Runnable{ 8 I+ T* d7 R4 j# k- u4 _0 s
  int i;
* G- x1 [; g: x' i: q' N- C  public void run(){
) B; r4 q# F; T9 U   try{
& ^( v6 b$ _  y% o( U       Thread.sleep(5000); 9 g9 P3 j7 V' H) r/ @4 p/ F/ C; V
        i=10; 3 o# B: a" m% V: s  Y& ~) ^
       }catch(InterruptException e){} % K0 A* k9 q7 [" G# V* l7 Q0 H7 r
       }
) p, g$ a& Y+ x       } # d' d* ^7 J. x# d; F! @; a
   public static void main(String[] args){
5 ?, t! e: w" D! t2 e      try{ * B: U* Q1 `8 c3 E1 N, w
         A a=new A(); ! L& Q( ?, ?& l- W# f- v
         Thread t=new Thread(a);
. Q6 F  i% |9 v/ J. ?         t.start();
( m# t0 V( x3 e& L; d; ?  17) 1 Y/ M# A9 }$ O0 C
      int j=a.i;
& O4 l$ M+ s, m) d& F4 _  19) # ]7 p$ G7 g0 H+ ^7 V2 d
      }catch(Exception e){}
: L& x& k' J  `  o& f      }
% i( I/ o: K+ E  T4 d. w      } 9 F9 q) K: X) u* L
  what be added at line line 17, ensure j=10 at line 19? 2 a6 h5 I# H2 R9 c, l7 j  z6 {
  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   
! h, Y# Y! J$ v  E.t.notify();  F.  a.notify(); G.t.interrupt(); ) N0 Q/ G# M8 ^" x
29.1)public class X{
- n3 b* i6 |1 p. |1 V. D  2)    public static void main(String[] args){ " ]- X0 G$ F# O5 \; a% Q
  3)     String foo="ABCDE";
, t0 m- q7 R) F0 c& {- }8 F  4)     foo.substring(3);
# f8 ^3 w% T3 T  5)     foo.concat("XYZ");
6 _) i- Y% A. N) b' ~/ U  6)    }
' f- n4 n3 _7 J% l0 `0 @  7)   } / Y# L) F* ^5 @$ j" n, R
  what is the value of foo at line 6? . X) i, ?) i3 t* W! }! [/ p: p
30.  public class Test{
. z+ \! L: I2 `" C# _5 C% |) x0 S   public static void main(String[] args){
$ n( j' l* `3 n- D$ L   StringBuffer a=new StringBuffer("A");
' e- K; x1 P2 y. O  f/ ~   StringBuffer b=new StringBuffer("B");
; K9 o, |9 b. o   operate(a,b);
' O! S. ]$ e1 k' ^* J6 G   System.out.pintln(a+","+b); 3 V2 |; |4 I7 o* [. r% u7 e5 N% b
    }
% W! n/ x- o; G/ T$ M( Y   public static void operate(StringBuffer x, StringBuffer y){ " Q- v& t+ K6 E% n  W) P* j2 {
    x.append(y);
- J) D6 y/ r( R4 j4 C, ~; _; a    y=x;
; O: Q' m( [4 }) }   } 2 e' R  `3 R! N
   } 4 f5 X4 ]* T5 ?& O5 p
   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享7 t' j' b3 b3 Q5 p0 k: e
我已下载。。。。。
4 x5 E4 I& Q' q+ 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-1-7 07:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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