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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题
( I# x* U( \; i& n" y1.        给出以下程序:; e* D. T/ r! X! ?
1. public class Colors {% K0 Z# ^; z9 K  `: Z" S
2. public static void main(String args[]) {+ p( M- A0 B. X$ g' B# [. l
3. int n = 1;' y& B+ A2 E# Q: f/ I, {( \
4. System.out.println("The Color is " + args[n]);* z" y. W1 H/ _5 V) I
5. }
" O. D6 \- a9 ?* d8 l6. }
2 O# K  E. q$ |2 {* K假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
; e. Y8 |5 [* Q: }. nA.        Colors red green blue yellow+ q* L2 b9 _# z
B.        java Colors blue green red yellow: b, ~! T# }4 w. c* C+ M
C.        java Colors green blue red yellow
- |+ z, m% j" r4 f* VD.        java Colors.class blue green red yellow( s2 Q% l+ f7 n' d
E.        java Colors.class green blue red yellow/ h; y8 [$ C# n0 x; ]+ _; b- F
2.        读程序:8 A6 o! Z/ y5 }- J% p. l/ S
1. public class Test{
6 ~1 B" [; f5 ?" @1 a2. public static void main(String args[]){
$ c; n% n4 f8 O( D6 N4 K3. char c = '\u0009';
! L! e6 X- [' k' O1 a2 V! o4. if( c == 0x0009L)
0 F- i6 n: g5 z  j. a$ z5. System.out.println("Equal");
# F& O6 F4 ^% Z  w$ O1 \6. else System.out.println("Not Equal");
+ [* b7 ?. ?$ J) V6 x7. }' O! L0 D7 V1 H8 S. D
8. }9 s. N0 J: ~* ?8 v7 R# i: x5 _, D& v
当编译和运行该类时,将会发生什么:' D& N7 [* a  D. a
A.        程序因为第4行将出现一个编译错误
$ q/ C2 ^4 x; `. }/ U* FB.        程序因为第4行将出现一个运行错误& }& P) J5 G$ K9 b9 n+ i
C.        程序因为第3行将出现一个编译错
7 i' Q) {. N, D7 p- l5 uD.        程序输出”Equal"& c4 G' u% E1 d, c# B
E.        程序输出"Not Equal”; B: I% {! z0 n; e9 ?, g
3.        读程序:
2 Q5 w& O6 I3 m; G( v2 O1. public class StrEq{
1 t! O& ~! N  n8 Y9 R7 L9 U6 B2. private StrEq(){/ |% e7 b0 }4 a, f; d
3. String s = "Bob";' E2 E- G0 J9 V( ]
4. String s2 = new String("Bob");
7 I- |' g* D. D) Q0 ~( T5. if(s == s2){. i: Q  r# C- C/ L  A3 e
6. System.out.println("Equal");
& U: G5 v5 g) f" F  J/ B) i! T7. }- w$ b6 m# C$ {/ p7 O# {( i
8. else{$ x; K. p7 ?7 s+ ?
9. System.out.println("Not equal");
; w: t" S# r1 s10. }
9 N5 l4 ~8 O# N" D9 f8 A' ~11. }
( \& y- ?- U2 e12. public static void main(String args[]){! l: r1 w4 y2 m8 t
13. StrEq s = new StrEq();. c2 M1 ^+ Q' ]$ S( t
14. }
+ D! p* ^) w+ ]15. }% f  Q$ }) N& R( i5 b  Y9 {
当编译和运行该类时,将会发生什么:
9 i6 w4 S- F- o# JA.        程序能够编译,并且输出“Equal”$ U9 \7 h2 D9 p9 Y: Y' s1 A- z
B.        程序能够编译,并且输出“Not equal”
! f& A& ^7 B/ E+ I( G2 D+ rC.        程序因为第2行导致一个运行时错误+ N4 e/ c0 M7 A4 _$ C: `
D.        程序因为第2行导致一个编译错误
, y  S: N3 q" y1 Y$ H4.        以下那个赋值是非法的:* O3 M; P7 t4 k8 Q( T
A.        long  test = 012;
' X8 W5 z* E5 }- M) T( @B.        float  b = -412;% S* t9 G* i- e
C.        int other = (int )true;0 l4 H. D3 @* m
D.        double d = 0x12345678;
- n/ v  G+ h1 O  t, x  \  e' M9 vE.        short   s = 10;. V+ ]. i  V7 m+ m% @' F
5.        读程序:; x% X. v) ?; ~- V# v* x
1. class CompareString{
. m$ P' ^% A8 Y+ g2. public static void main(String[] args) {
; ^* p0 {) a7 h3. Integer x = new Integer(5);
0 o$ g  k5 k8 D; `. U4. Integer y = new Integer(5);" S3 d: `4 \- G8 K$ v
5. Integer z = x;
: Y) A$ k# t9 @' A) D3 I6. if ( ______ )' ?0 C" @: X4 H. O
7. System.out.println("true");
- U3 B& ~! A7 f- J5 R8. }3 v% n& B8 b9 H8 G0 b
9. }" C1 W% p" m! l) k
以下哪个选项填入第6行后,不能输出true:
. {- Q, B" t) a4 y+ @" L( E* c/ O9 sA.        x==z
- @( h3 K, l* B: c- GB.        x==y, l( [" g5 J0 ]$ `' a
C.        y.equals(z)
) F! w3 q0 F+ H6 P. h( W9 ^D.        x.equals(y)% @& @% D" d- [$ b
6.        读程序(双选):
2 J% q! _" [) u8 Q8 }+ }1. public class Declare {
9 c( c4 V; P: F! Q# j: ~1 m2.
0 ^" d' Q/ ~6 T7 k9 x+ ?3. public static void main(String [] args) {9 K; J( G0 s4 c  }  _8 w1 [
4.9 f& h' u4 f" J- Q
5. System.out.println("The variable is " + x);
. Z& {: v# \. ^6. }5 M) {  A) f. m! h: G0 I
7. }% W2 e- b. [8 a5 x2 Z1 a
以下哪个选项中的代码可以使程序编译通过0 Y9 Q. G% I, c  E9 w. J: W
A.        把“int x;”放在程序的第2行$ j0 p5 a$ k& M. q0 t3 M/ F
B.        把“int x;”放在程序的第4行
% K% S7 l# J4 J; QC.        把“int x=5;”放在程序的第2行
' l7 a- x; G' n# a9 q/ P7 j# |D.        把“int x=5;”放在程序的第4行
$ f( M$ I: R& a$ ^& E" q/ Y- ~E.        把“static int x;”放在程序的第2行) q$ S+ O7 c2 G: H5 X# b* f

3 d4 {- p9 _6 Y+ t" a4 n* j- P0 l8 C( h

% o8 j2 {. a* V* r7.        读程序(双选):
- q* F6 j# }; b& D7 a* \& K* p9 C1. public class Child extends Parent{) T6 @' l7 @! h( _
2. int a, b, c;
, `9 q1 {, D6 i0 w) n3. public Child(int x, int y) {: C; F/ `& G& R8 {# y# Y) U
4. a = x; b = y;
0 t+ ^- ?6 }$ F  S! \/ C5. }3 L  Z+ x) |; H" f- o. }
6. public Child(int x) {, p% X  ?3 e2 U1 ?5 f
7. super(x);
% b. w5 ]: G' k' r/ S1 M* r2 t; L3 j% R8. }! u4 p" K6 P) m* ^
9. }9 h5 X( Q7 f8 V8 G' ]- P9 s! |% n3 ]" d
为了能使该类编译通过,下面那个构建器必须出现在父类中:
: S+ }5 s2 q9 w6 Q$ IA. public Parent(int m,int n)2 E6 Z: K9 Q$ L1 n
B.public Parent(int m): ~6 K2 s' Y( K/ P2 N' a4 W
C.public Parent()
, g/ [1 ~& U7 q, n8 U( A% V3 SD. public Parent(int m,int n, int o)
* d1 L7 v( w# Y8 C2 d# R8.        读程序:
% l$ ]% [1 D; l1. public class Derive extends Base{
2 Y4 A' l3 N. @: U6 K2. public static void main(String argv[]){
- m3 C1 a; W% B! U" @7 Y3. Derive a = new Derive();
% i% o" n. ?. \5 S4. a.method2();# i* j7 ^, _4 n  T+ ^: y' d
5. }
) x6 w7 _9 ]7 m8 O  y8 M" s6. public void method1(){
- U* K" h* @6 B; K1 Y7. System.out.println("method 1");
' f/ z1 u7 F% s* L: X0 X/ L8. } 8 I3 `/ T) y1 Q% e
9. public void method2(){- ~# j5 ?7 C+ y+ _
10. method1(); & {% a  G- H% P- Q: b' s9 o5 c
11. }
& k$ Y2 K! K7 `, M  `! z12. }
/ Y/ e* L( U1 w, G$ N# h13. abstract class Base{
" m6 i' [2 E: _, I( m7 m8 U14. abstract public void method1();2 I' F+ Q3 }6 h. \% b: E9 W$ r' M
15. public void method3(){
1 v- g" `3 @- F' Y& U* B16. System.out.println("method 3");
& V* a9 }0 `0 w6 g& E2 \17. }
) m9 D! v4 g, Z" P$ v8 N}, K( u: N. q9 W8 m. U) z
当编译和运行该类时,将出现什么:3 e2 u2 @" W4 B" J: c: A/ ]
A.        程序输出“method 1”! K1 e6 [+ i( x/ }; t3 j
B.        程序输出“method 3”
1 ]% T) D) W" C* m3 jC.        程序因为第15行而出现编译错误
+ g# Q  [. a' y- S: lD.        程序因为第15行而出现运行错误
1 P: |6 M$ Q& w) h9.        以下哪个接口的定义是合法的:
2 |2 A8 ]# P* ^6 U* u4 zA.        public interface A {int a();}
6 U3 p* u, S# `! a$ Z6 }. kB.        public interface B implements A {}
; Q4 O7 {" D; |& xC.        interface C {int a;}
. |+ d; _8 S& I& ~, ED.        private interface D {}
& P0 M) }! M# C& t; x- E3 B7 Z, K10.        读程序:
7 I# ^& B) v  r& _# j1. //File SuperClass.java
4 l. o  N$ }6 L- m' _& c9 [2. package MyPackage;  r7 C" P6 w4 E
3. class SuperClass{
! r! _# r4 a9 c# N8 O! h! x1 p" ~4. void myMethod(){/ w3 j! X" ]2 j) c, r, h6 r- x
5. System.out.println("SuperClass");+ i$ h3 Z, A" [: |3 m5 c
6. }' l" `) \: ~- W! L8 g& m" c
7. }
$ [& a2 R5 L6 b' R% P9 _8. //File SubClass.java
( W" Q; ~$ f& c" f& k$ X& B- t: `/ {9 s9. public class SubClass extends SuperClass{
* e. Q- B( [5 P1 F10. public static void main(String[] args) {# b6 T; f3 O; a4 i! _) ?; Y0 a
11. myMethod();
" p5 Q; L! [/ L' q( v1 G# y; {12. }0 p8 _4 M& H5 D2 ?6 h0 u) ]; D
13. }, G7 D  `" y% `/ p
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:* p, p9 }) |6 v
A.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
8 [' T% l7 m, z2 g  @0 `: ~B.        两个类都回出现编译时错误
/ V, @. L" L8 DC.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误+ ~7 l; p  \, I5 h# z
D.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误+ X) |; F& R6 L& h6 l
11.        读程序:
+ }2 ~/ \" a1 p6 K  E) D9 n1. public class Test{& g1 R+ d2 n: B: K) L. V
2. public static void main(String args[]){' F; c, Y* p2 g0 p! J" Q" [
3. int[] i = new int[5];
5 s2 X1 Y( I6 B3 K% a) Q4. System.out.println(i[5]);
9 p( P' j- j1 v2 R" L$ s' P5. }
. V  d2 C  K, _$ R$ r+ A- U9 \2 J' e6. }- b" J* p% F3 C7 Q% \2 [0 F
当编译和运行该类时,会:
" p0 p/ @! f9 D( g3 H. g" `- bA.        出现编译时错误0 G+ A+ @6 }- A- i
B.        出现运行时错误* N( E* h6 e6 I
C.        输出0" t1 q8 w9 K+ S6 K5 U5 E( e( }
D.        输出null
0 q4 a6 U+ S& {7 K7 @' j12.        以下哪个选项是正确的数组声明或初始化:
( l! q2 e! P$ A# {! G6 M! HA.        Array sizes = new Array(4);
0 o+ F) |: A6 O" b7 E8 V* gB.        double [] sizes = {1, 2, 3, 4};
% I0 M+ O  {' o; ^0 B: g1 ~C.        int [4] sizes;& ~4 |: W9 L! N8 e" Z* H
D.        long sizes [] = new [4] long;
+ u" p2 P& ~# _* [, o" v13.        读程序:# |: }$ L- W% z3 L
1. public class Initialize{
. f) o+ y) S( {7 H& K2. int x = 200;6 s/ a( U2 {6 p0 ^2 Z
3. static {
9 o+ t  |8 M" o/ y2 y. ?4 O4. int x = 100;! S3 ?# r# _- R& \9 b- n
5. }# r9 Y4 Q( o- W
6. public static void main(String[] args){
9 J$ h, O+ U: L8 H+ t: S+ z7. Initialize init = new Initialize();& U5 h! P, e  S3 }3 u
8. System.out.println(init.x);* G* z5 v9 A7 Y1 c! ?1 [
9. }
! `# C) U( O% A7 n7 |10. }( J+ S8 c; R; Q- b
当编译和运行该类时:
: R! |% m, f7 ~0 H# d/ B3 PA.        程序因为第3行产生一个编译错误- T1 P9 o! g# F* z% e+ y
B.        程序因为第4行产生一个运行时错误5 z, b$ K! B+ ~1 Y; P9 K4 ]
C.        程序输出100& q" s7 K# x+ S; N& i; b
D.        程序输出200/ L" a3 e8 X; d/ |
14.        读程序:$ a" \6 D( }4 [5 n) I' L
1. public int abcd( char x) {
0 r% a; G/ L3 G6 {7 ~2. if ( x <= 'M' ) {
3 C1 T7 b! c1 m3 X( z$ A) @' V0 D3. if ( x == 'D')
) H. g/ y0 z" r( M. H4. return 2;
: l, v. V; E7 W) @6 ]8 B5. return 1;
# B" b/ n+ _3 W. Z6 w6. }( X% ?" f' Z( }0 g( D- [' d
7. else if( x == 'S') return 3;
+ h* `/ C* s$ R! b# Y4 f( [- F8. else if( x == 'U') return 4;
7 O6 `0 O$ b0 q9. return 0;( v/ f4 G& ~5 O5 j; M' h
10. }
" F- w6 ^' v  w在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1: t& S- a8 E4 J% t* s
A.‘X’/ u7 W! j- \5 o7 M- N' }' ]$ }
B. ‘A’
( h' _, c# R; f# UC.‘D’
) f/ ?; r1 v3 D5 {D.‘Z’1 X+ J+ ^- p  H* A
15.        读程序:
; y+ o7 D% Z* [- f0 G1 \8 K/ @; u1. class TryTest {+ @2 k$ D2 o- w& M1 `- Z7 v
2. public static void main(String[] args) {5 ~! S% f) R" k/ `2 _; |. b
3. try{
+ v) h, U) n( g1 u, w* c4. System.exit(0);
$ q! U  O( R1 K7 w5 v4 W8 C5. }) y; c: a4 j, R7 g4 |
6. finally {- U' Q1 F/ H: [% b8 d1 H( y
7. System.out.println("Finally");+ W! e, |# o  }1 `# h( m7 Q# T
8. }
3 }" l) ^6 p9 y  d0 S9. }
, D. e# t0 [* J* b10. }2 W: v9 S- ~) h2 M# y: J% H! I9 t
当编译和运行该类时,将:
! _" U/ V5 I9 u# y$ O1 oA.程序因为第4行出现编译错误
* n4 h' C* A8 y2 |3 AB.程序因为第4行出现运行时错误
; o9 a! Q( E: z) V, {/ LC.程序因为第6行出现编译错误
5 Q& c- O( v3 h* D1 r- C' KD.程序因为第6行出现运行时错误
/ M4 c/ ^: J# |# S3 f' M/ v# p6 B' a( NE.程序输出“Finally”
+ r  h* y3 K6 U& }2 N. \* bF.程序可以运行,但什么也不打印
7 x9 y% j2 s5 A0 c# \- D. x3 O' w. {7 N- Z7 a7 P, N
16.        Given the following variable declarations:' y* E6 `' N/ V8 Z; t
Boolean b1 = new Boolean(true);
2 k. X" H5 u# eBoolean b2 = new Boolean(true);
: n7 {: T6 n( v3 s/ cWhich expression is a legal Java expression that returns true? " i; }- O* g0 U# D
A.        b1==b2
: j% R8 `* `! Y- RB.        b1.equals(b2); l5 q5 M# H6 H4 c$ N
C.        b1&&b2
8 H1 ~# s+ g6 J( g! z3 z1 P% GD.        b1||b27 W* V7 }% p. k) _/ D- Y
E.        b1&b2
$ u: L  Y) Y  n, BF.        b1|b2; V5 _( b  F  K5 T0 k* l$ w% J) f
17.        Given: $ A1 _6 M7 A! {- F
1. public class Employee {
8 I4 v& T0 A: o5 f2 T2. / T5 i; K! P' g& w2 z
3. }
2 o: U8 N: r2 W5 F7 ~! `4. 1 E; i1 U, L4 ~
5. class Manager  extends Employee{) J. h: q# z0 ^  p- N
6. }
) M6 i  u# }  `! ]2 ?2 wWhat is the relationship between Employee and the Manager?
1 c' [/ H4 v7 [' ^; T  {& L3 wA.        has a2 v3 S0 A/ M7 m: @  w
B.        is a) w, K9 N, H" U- o8 m  R* o
C.        both has a and is a
' ~$ p( O  b3 v5 S) p7 RD.        neither has a nor is a
! q2 u+ M& [- {, D18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
( b% F7 [0 t( e, R. J9 c( \A.        BorderLayout% l# e: e/ F3 q) `
B.        FlowLayout% u2 L  ]5 N. k! W* T' ?$ m  G
C.        CardLayout# n; G" F; x3 A) a
D.        GridLayout
4 I1 N. P& t2 _7 M6 m19.        Which of the following AWT components can generate an ActionEvent?: I0 m5 a9 I! t  g3 h
A.        java.awt.Button: T* J' O0 I# q: o+ v
B.        java.awt.Panel' x+ f2 r+ O4 X8 y/ v6 T" ~. K
C.        java.awt.Canvas8 i+ b4 M& R  V
D.        java.awt.Scrollbar" p! W& g5 C. r. B5 F6 Z
20.        What kind of Stream is the System.out object?
! o1 t6 R3 a/ e9 wA.        java.io.PrintStream
) Q' `% f  Q. Y' H; w+ u5 P2 _B.        java.io.TerminalStream
* j" E. w( i- m3 S; a3 G$ QC.        java.io.FileWriter
: J8 i/ Y2 a; g2 T$ i) }D.        java.io.FileWriter
% w. P' J3 q: `5 w' w3 \21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)3 a5 O/ H0 V& H
A.        java.awt.event.FocusEvent2 ]* c2 k, y" V1 g$ B  X
B.        java.awt.event.KeyEvent  M' W8 k" r/ e' h# M0 I: U
C.        java.awt.event.ItemEvent- |5 X2 E3 f  Y0 d9 ^9 R% G3 b+ C
D.        java.awt.event.ActionEvent
0 z; H' `' }( J( g% X# A22.        Which of the following methods are static methods of the Thread class?(双选)
9 {! S" i/ ^/ f2 I+ d1 x- n4 @. nA.        sleep(ling time)
% B% o% _1 J7 Q" H& N  ?B.        yield()
6 }, Z7 ^3 _$ ~, p2 DC.        wait(); `( F: O. Q. F5 x" I8 t! o
D.        notify(); j) j9 s, D/ S
23.        Which method do you have to define if you implement the Runnable interface?8 f+ E4 S6 S8 D
A.        run()/ G) J# \$ F% M! s& m
B.        runnable()
4 q5 p! Z0 ^8 U; B$ o, {C.        start()
9 w5 r  C% G9 a" {6 qD.        init()
% `  w/ }% k  a7 C2 s# tE.        main()
1 S6 k! e% _1 d3 P- G1 T24.        Given:) ?8 T  X7 b, A. P
1. class MyThread extends Thread {3 j5 v3 t$ Z3 w+ X7 b, m
2. 1 G9 S; z5 |# w) S, {. W
3. public static void main(String [] args) {
8 b4 h4 n/ y- J# O, A4. MyThread t = new MyThread();
! r* Q5 }- m0 A' G9 h( n5. t.run();
" j. y6 \& T. d/ {: {) n" W$ a6. }
5 b+ s+ F  |: e7.
/ V  s6 ~( T# M1 x. Z" ?  H8. public void run() {
: i( y5 I; ]1 a- ]2 ^8 g9. for(int i=1 ; i<3 ; ++i) {- e, A) d5 C  h) \' |" g+ ?$ t: q
10. System.out.print(i + "..");& ?* u* j. o) G" a2 m
11. }0 \4 A  v7 X, I; J1 d
12. }( x" Z4 `* i" ?# b. ^
13. }
4 T, F5 T- {. \+ \4 D- T; n2 \What is the result of this code?C
: v3 o. M) q2 X! r) f0 H# DA.        This code will not compile due to line 43 k2 c! m# Q7 j9 q3 `' ]; o
B.        This code will not compile due to line 5( J/ S, S  p9 h" X
C.        1..2..
# t5 @; T& B! E  z: ?4 gD.        1..2..3..7 T( ~% e% s$ T
25.        Given a local inner class defined inside a method code block, which of the following statements is correct?/ X1 S' D1 u  [
A.        Any variables declared locally within the method can be accessed by the inner class! u* e% w% w$ R+ g
B.        Only static variables in the enclosing class can be accessed by the inner class. [' n  U& g" }6 k% f0 g2 {
C.        Only local variables declared final can be accessed by the inner class
- I" g- T& c, c8 R3 s. [D.        Only static variables declared locally can be accessed by the inner class.1 q7 d/ O! ^8 E1 a* c. a

* ?  h0 Q& I7 i: Y6 q6 i* s6 q+ o; `* ^1 H+ {  h
5 E; F+ o# P  X8 Y$ A: @
26.public class SychTest{ 4 o9 t. T3 N! m! }  n
   private int x;   i) Q0 E. K4 x1 e+ h0 }' N
   private int y;
- Q  _' F" y; I: D) p* Z6 x3 `" o   public void setX(int i){ x=i;} & I+ F# y$ I: A& l, P1 b6 e# v
   public void setY(int i){y=i;}
3 z  e* p3 s/ D7 |  i% r1 P   public Synchronized void setXY(int i){ , `" B+ P' P* `5 s* K8 b
     setX(i);
' {  A* W3 M  _: K     setY(i);
1 F  o5 o& }2 ]   }
2 ~% k# |) l1 x  i   public Synchronized boolean check(){
( j( y% L: l& x8 w        return x!=y;   ) E7 S6 h7 e$ U; C1 M) A1 ]
   } 6 F) a3 s, y" {' d0 c
   }
! t3 c' s" m# x5 X* f    Under which conditions will  check() return true when called from a different class? $ o4 I3 P; H" v- Z% U5 b6 [  X; h+ X2 y
   A.check() can never return true.
1 \* ]1 r, |# Z! t   B.check() can return true when setXY is callled by multiple threads.
- t/ p3 c8 C+ t. H8 y; a   C.check() can return true when multiple threads call setX and setY separately. 8 h3 B0 P2 [6 m7 P7 W# F; Y( Y% J
   D.check() can only return true if SychTest is changed allow x and y to be set separately.
* J2 n$ g) d  |$ k5 p. R% D8 p0 r+ h3 D2 [8 d
27. 1)public class X implements Runnable{ & P# U, o+ e3 P" g3 k7 s: z* |* m, [  H
  2)private int x;
% u5 R! Q2 u; Z. y  ?. ]  3)private int y;
9 ~9 M3 t" p+ H  [3 [2 \0 R4 ^  4)public static void main(String[] args){
- U- P% g- p2 q3 I, z/ ~* |5 V. J9 ?  5)   X that =new X(); 5 ]# s" e" H+ e" b
  6) (new Thread(that)).start(); / m2 T% ]+ y1 G; o& {, K/ |
  7) (new Thread(that)).start();
) C! a4 P7 e4 k0 O* A   } 9 s7 |9 Z$ h* o! k
  9) public synchronized void run(){ ; X- T3 g) D1 M$ g' J. C. s6 r
  10)  for(;;){
7 n% D7 k' e5 U5 W- D  11)      x++; , n. \1 U: O. R; y' @9 H
  12)      Y++; - f0 _/ }- h8 }/ K( x* e$ ^
  13) System.out.println("x="+x+",y="+y);
& k8 ]( I) ^1 j% t4 K: G' F# D. C  14)    } - e- W2 y/ m  q( K
  15)   } ! v$ D" Y3 h/ d! N  `4 T/ g8 Q$ d
  16)  }   . ]" _  |' s) Z6 v- o1 M" i8 d1 l
    what is the result?
7 O' \, E# B. W  A.compile error at line 6
% G6 j4 p) t) y9 h  B.the program prints pairs of values for x and y that are
" |% P" l9 B5 T# ~: W    always the same on the same time
1 Y* J# U+ ~1 Y8 _4 o5 u' x, y
* `. x0 v7 t6 M" ?; r- T0 L28.class A implements Runnable{ $ |4 A/ S& p* ?* p( o4 m+ R5 F: @
  int i; 6 _  m" ^, _4 k
  public void run(){
0 E/ X5 @8 b7 o. g. J   try{ + D5 b/ h9 \5 B
       Thread.sleep(5000); . S# ~" V" C1 E
        i=10; + `+ [7 E7 y0 `# l' k
       }catch(InterruptException e){} 9 F# o5 W$ n3 P; T$ S% A+ m$ N
       }
& Z" ~. |3 D- z3 y' W  m) e       }
2 a# O1 `7 n* b5 T. I) ~   public static void main(String[] args){
, }) b% X0 Y' c% p3 W: e      try{ % O, d( C+ Z& ^8 y4 {% ~5 Z7 ~" d
         A a=new A();
$ T. H; e# p3 R' K) r4 f6 v         Thread t=new Thread(a);
& \9 Z7 _2 l! d4 B, @; z         t.start();
% F+ L. r. H( Z) C9 b8 A) ]! W  17)
% S. _. A- _+ A: w) b      int j=a.i;
+ d3 b/ z! f  ^, \- J7 W2 Q  19)
* f0 f4 Q* p0 r4 u( m      }catch(Exception e){} 8 t' |- d) ~% |
      }
6 ~$ ^! @- l5 O) _9 S9 {      } 0 W0 m* w2 P. A& R) A/ F. ^. J
  what be added at line line 17, ensure j=10 at line 19? ( ~+ q2 Z* C; O0 u, m8 z
  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   
) u6 ]3 _* c) T# j+ q8 Z! l  E.t.notify();  F.  a.notify(); G.t.interrupt();
' z) `! s" O/ i2 a2 m4 u4 V29.1)public class X{
7 ?  W6 k' d$ D; h8 v* m( w; t7 w. Q% g  2)    public static void main(String[] args){ ' r; l/ a1 c9 S0 j- g
  3)     String foo="ABCDE";
7 a+ b5 z4 Z6 X/ ?- \3 {  4)     foo.substring(3); 4 j. a% d' g) v) }2 u
  5)     foo.concat("XYZ"); 3 |7 i5 W$ d/ {- O! X. m: [. M# Q, Z( F
  6)    } $ J$ Q/ G9 Q: Q4 k
  7)   }
2 P- l2 p6 m: s* {" V" a  B  what is the value of foo at line 6? 1 t- n7 n. C+ V4 l2 V- L+ S
30.  public class Test{
. @8 f5 g: n+ p- n/ ?/ ~   public static void main(String[] args){
1 K/ T8 H" O7 ]+ p* V6 w) G   StringBuffer a=new StringBuffer("A");
$ G3 p3 n# g- w- {6 _( C/ {0 x   StringBuffer b=new StringBuffer("B"); : O2 o' _8 |% p# o5 N, p2 `
   operate(a,b); . |+ |0 b' r7 S, s0 r% m- O
   System.out.pintln(a+","+b); ) k& _7 t$ V/ O, r8 {2 v
    }
  ~& ]  N; f. ?7 f   public static void operate(StringBuffer x, StringBuffer y){
! j8 M7 w* c6 |4 k1 c    x.append(y); / N' y* r! y5 j1 d/ r
    y=x;
3 V+ ?% S% j- X5 I6 k8 Z; J( ]   }
3 H8 u5 x8 k5 e/ E0 o  N4 R1 e   } ' d$ B( F' W. D# {% H0 J% Y- Y
   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享
, i# h( H8 j& Y) F+ O! g7 c我已下载。。。。。- l" N: ~7 d* Z' N3 z$ d7 ~% ?
特感谢您的大公无私
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-24 02:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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