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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题
! L) a1 Y! ^" n1.        给出以下程序:
# O7 r( Q3 _6 L- E1 p1. public class Colors {
9 z$ S- g  i! l9 T9 {5 H2. public static void main(String args[]) {
$ L* k& B( c  Y2 q5 K3. int n = 1;
6 G) }7 Z0 i. ~5 K4. System.out.println("The Color is " + args[n]);
7 }* W* H+ D* ~% a" }3 j8 _5. }
, x4 n" n7 {( r6 e- G2 q6. }
# a5 s2 }5 C  C5 R! j9 \3 [假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
  W  I4 b$ Z! u" fA.        Colors red green blue yellow0 o9 i7 M3 h2 {; C
B.        java Colors blue green red yellow% u5 c, |" Q1 J1 g
C.        java Colors green blue red yellow
( \/ L5 q5 ]/ [D.        java Colors.class blue green red yellow2 o( n( F: E" y4 W& y$ i/ V
E.        java Colors.class green blue red yellow
' W1 T7 o' i3 b8 {2.        读程序:& o1 j' o9 W( h  n+ v* w- O" U: c/ w
1. public class Test{+ o. F- ~) u/ S
2. public static void main(String args[]){6 x5 X. Y9 K, r2 p: j8 d
3. char c = '\u0009';
# i2 O0 s" W; @; U$ F4. if( c == 0x0009L)/ M1 N9 m% {: p3 Y2 \
5. System.out.println("Equal");
0 F3 Z. c0 y$ M8 P4 |6. else System.out.println("Not Equal");& {# @8 z0 ^+ W) m7 U' {! ?
7. }
% Q* p" X: ?% D7 ]8. }' Z' j( V1 X2 L9 Z$ `# n) \( G8 _
当编译和运行该类时,将会发生什么:
  M% w* V- l+ f- T! S1 FA.        程序因为第4行将出现一个编译错误6 w) ~: n" E. _1 l1 r3 {3 L1 n4 \" l
B.        程序因为第4行将出现一个运行错误! j% p' Z/ h# Q3 w2 W
C.        程序因为第3行将出现一个编译错! Q, ^9 _8 {; d
D.        程序输出”Equal"" Z9 `' e" h$ _1 _1 W0 N  I  F
E.        程序输出"Not Equal”
9 }* a( O* ?& h. ^; p, `3.        读程序:% g, `' L" d* g* F3 S
1. public class StrEq{
  u9 G8 j# Y; f% x; L2. private StrEq(){6 i( Q) L4 w& C1 O  r
3. String s = "Bob";( }) j0 R4 E: ~7 m# o2 J- c
4. String s2 = new String("Bob");* }7 G2 p/ a( Y! p4 i4 r
5. if(s == s2){
9 z- Y9 l5 {' ^6 M) e4 b6. System.out.println("Equal");7 k# N+ u9 o0 U+ d
7. }
! ?* ?1 |% T  P3 A! \8. else{( V  Z6 E* |) L: Q
9. System.out.println("Not equal");' O/ D8 R" _  r, D' h  n
10. }, R, I" n' P9 r# S1 o9 B
11. }
! ~) q. D8 `% ?3 t( y. h& U12. public static void main(String args[]){
" I1 K" V$ b2 w' g/ R13. StrEq s = new StrEq();/ Q: m) Y6 A9 Q' J  q" `
14. }
7 E/ ]: o& Z7 {* R1 W- [15. }( r7 f; h3 M* ^/ N6 N1 U4 n
当编译和运行该类时,将会发生什么:
- t& b' B/ E7 B. u- YA.        程序能够编译,并且输出“Equal”) o8 o% ]- `" h+ t3 }" R/ I3 n) o6 g
B.        程序能够编译,并且输出“Not equal”
+ V/ C0 k9 _: v  K6 K( X- I3 q. ]9 ]C.        程序因为第2行导致一个运行时错误
' M* o+ Y0 G7 c7 zD.        程序因为第2行导致一个编译错误
. G9 ^0 C. u( x" P+ o- j% g4.        以下那个赋值是非法的:7 ^1 V; C7 _; z7 R" k
A.        long  test = 012;8 v  a: s, j7 g3 P0 U
B.        float  b = -412;
# ^* @6 N- y; O7 \+ ?; V/ ?% TC.        int other = (int )true;* j( Z% D$ r! J5 n+ _5 b
D.        double d = 0x12345678;
2 G; p% W, L- B3 {6 BE.        short   s = 10;; N6 I/ I1 m% P) p
5.        读程序:
7 W' d2 ^( _8 Z* Z+ {* A1. class CompareString{8 M+ l; D1 G2 I( f
2. public static void main(String[] args) {
% u6 a3 b, X' |9 ?3. Integer x = new Integer(5);, X; E7 h- B# \; N; h
4. Integer y = new Integer(5);9 Y9 Q; N$ ~: |' |
5. Integer z = x;
- ^6 b' |& x0 g: s3 u1 w3 J% c6. if ( ______ )' K! @9 `* z: S4 c# l2 z
7. System.out.println("true");, ^; J6 y& n' @
8. }, |. g; U& C4 l1 X- R
9. }
5 g. z  Q3 S1 j9 g' }以下哪个选项填入第6行后,不能输出true:
! D* n6 ^( p2 G) }0 bA.        x==z! `9 j+ r# o) O+ H+ Y5 O
B.        x==y
* c* ~, U! S8 i  m8 w) L+ dC.        y.equals(z)1 g, u  x6 }5 ?) s. a
D.        x.equals(y)$ g: T) v# v/ ]" l! \. H2 b% e7 y3 U
6.        读程序(双选):
# c3 d9 L  `9 F) L1 L1. public class Declare {
# \1 d$ H% [  f" q' Y$ h2 E& x2.
. y8 U) `) n% @5 B) Z5 f3. public static void main(String [] args) {
5 n0 Q$ R5 c" [: N2 g4.
& D* E6 ^1 r$ z0 n5 r* |" p5. System.out.println("The variable is " + x);/ w2 P; J4 U* _1 ^& q$ F5 {* Z0 U
6. }. Q; `1 H; C! S+ s. C' m* Q
7. }
5 h) u. f. ?; Z3 J3 P+ n+ [以下哪个选项中的代码可以使程序编译通过& Z9 v, ^- a! x, \, \  o
A.        把“int x;”放在程序的第2行# f$ }9 S7 _& ?
B.        把“int x;”放在程序的第4行$ l9 @( z0 m- y' C; p9 x/ Q" ~6 t' c7 `
C.        把“int x=5;”放在程序的第2行
- b4 `) ^7 F- y0 F% [$ YD.        把“int x=5;”放在程序的第4行
; s% v' @$ G; D& d8 L( H9 YE.        把“static int x;”放在程序的第2行- n* v: e6 P7 Z5 d
4 `  X/ {6 |; \  Y/ a; B
5 q( F3 O# m+ t" v. A9 M1 L
" P# \* x/ U* q, a% D/ j
7.        读程序(双选):3 a- r5 J/ ^) M4 s3 P
1. public class Child extends Parent{
# b' E8 p( M0 @2 ?% R/ ~; ^2. int a, b, c;
% o  e& j) h6 g+ ]* \7 ]/ b3. public Child(int x, int y) {& v8 ]2 \- y2 [% q, k& L
4. a = x; b = y;) ]. \& j8 H7 K5 Y6 q
5. }9 k8 p) S( _& a; d
6. public Child(int x) {
, f7 h& N4 D; ^& S5 k, c7. super(x);
$ z/ A& Q3 F! T3 z! F8. }' j8 y1 J" J' ^7 l' @( K5 [( F# O
9. }- v7 V/ l  ~9 t. |# o9 I6 C
为了能使该类编译通过,下面那个构建器必须出现在父类中:1 h: w  o6 ~6 V# O
A. public Parent(int m,int n)
8 e: ^1 m' S1 G# v* j" J7 rB.public Parent(int m)  s# |+ E: W6 t# ^" P
C.public Parent()
( t) u/ J! M( F# D* S: hD. public Parent(int m,int n, int o)
  ?$ n* t4 R& S8.        读程序:9 |5 y. e& D0 O- j3 _4 P6 H
1. public class Derive extends Base{
- I; Y, @$ c5 f; m2. public static void main(String argv[]){0 j0 G' M5 o8 D
3. Derive a = new Derive();
/ V8 _& w! h6 L# y. k  V; a5 \" j4. a.method2();
$ B% H; @! H+ o8 z) n5. }% v- Y9 i" Q  J' A; x* C) l
6. public void method1(){
% y: p. n- B: u* |6 X- k7. System.out.println("method 1");
- ^, l# L' J! `5 c( G8. } ( r& [% m4 o% ]  b/ z
9. public void method2(){9 W, _  a. e! L' r" l' C
10. method1();
& |( k4 |! W7 h7 n; @: r% s11. }4 {( i' X3 t6 V/ t! _4 l
12. }. h1 z0 i; J7 v. F  X2 C
13. abstract class Base{" g" G) C' `/ M7 L* }+ ]6 L
14. abstract public void method1();  w/ J" O# i2 a5 {8 j0 |
15. public void method3(){/ r, \/ N$ e0 q( f
16. System.out.println("method 3");
1 D3 i  F' P, ^. T3 m& _0 z17. }
) n: m" @; O1 ?}
6 e2 O/ q& \8 V: X当编译和运行该类时,将出现什么:5 x2 P( A' s, T$ }
A.        程序输出“method 1”1 T3 m6 `0 {; `0 r% f& I, d3 s
B.        程序输出“method 3”7 \, {4 w- b  G0 O. I) \( l
C.        程序因为第15行而出现编译错误
5 `4 F5 E/ j. G; b7 a0 k  BD.        程序因为第15行而出现运行错误$ G- w2 [9 y+ e
9.        以下哪个接口的定义是合法的:& v; m# ~; r* }; j
A.        public interface A {int a();}: ]( b4 i7 n) ~" k
B.        public interface B implements A {}! S; ~# Q7 f  I$ Q1 E" O3 p& D9 D% H
C.        interface C {int a;}' \; \4 W+ ]: z
D.        private interface D {}. q) g* D* ^* E+ a: U
10.        读程序:
" {5 E" U$ C" j" n1 H1. //File SuperClass.java+ R/ P* J# k, l: a$ b5 z5 Y! y: [7 @
2. package MyPackage;
( e3 F. \! @, x5 d& ]1 Z3. class SuperClass{' j* g4 P3 E+ i
4. void myMethod(){, y/ r5 f% ?; R9 L* }
5. System.out.println("SuperClass");, W+ d2 z3 `# A' {; @
6. }
1 `' P$ a: s: `& A% y7. }% k. n  v+ M# P' O1 s6 e
8. //File SubClass.java
" P8 j6 y  u7 ]! i3 E9. public class SubClass extends SuperClass{
0 K! c$ Z1 z2 H: k% _+ W; H) C10. public static void main(String[] args) {
- b( r" P- W1 O- A  O6 [11. myMethod();9 y; S, c6 N& D- L6 V6 A! x
12. }
5 D# p  M; ^2 Q8 r. u- H13. }
" I2 i: D) E: I# L当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
  s5 k$ `# x$ J* K: EA.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”) G8 i( e/ e9 H+ t
B.        两个类都回出现编译时错误
$ E' x3 p$ V4 ~, g; JC.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误0 J" z) ?' S. p( q  S
D.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误! v( U0 j: I8 d4 c4 [
11.        读程序:6 t$ m. r  K- R- W" J; q
1. public class Test{! I' J  ^) e6 y6 x2 }
2. public static void main(String args[]){
3 {0 Z* a% h$ H# {6 V, ?3. int[] i = new int[5];
- w. z- b: N  C) N( E9 U7 q2 [* u4. System.out.println(i[5]);1 y$ ~5 }/ s9 |; i8 G
5. }
4 i* [8 x  T* }1 A% @# i' r2 W# f. D/ z6. }
% K; E$ m% S: ^9 ]/ [, F4 J5 {) ^当编译和运行该类时,会:
" k$ s0 I1 r! b3 f9 O1 aA.        出现编译时错误3 `2 u" C( K! E% L5 R. D
B.        出现运行时错误
: M3 S; Y- w4 b6 W4 H2 f2 jC.        输出0
5 \% M7 L5 h9 o4 g& OD.        输出null- B6 U6 T% x1 [8 ?4 e
12.        以下哪个选项是正确的数组声明或初始化:
0 U2 u0 X  Y* f1 AA.        Array sizes = new Array(4);
; o; R" f) r( A6 jB.        double [] sizes = {1, 2, 3, 4};0 }# r0 }" N. m8 E* X! y9 p3 e& f  o
C.        int [4] sizes;, p; F7 `6 r1 `. ]3 o
D.        long sizes [] = new [4] long;
1 C/ H7 X4 s1 F# K13.        读程序:3 n% x( y( l, Q+ w" L: g
1. public class Initialize{
* \, R1 S1 L1 J0 T% Q2. int x = 200;
: x+ h- Z. x6 q; g$ G" A9 ^* Z3. static {  X- ?; O5 V$ C1 B2 L6 I
4. int x = 100;
+ G. w% D0 N& z# M  k5. }
( C( W' q) K+ ^6. public static void main(String[] args){
7 P1 s$ r1 }$ ^+ C- K7. Initialize init = new Initialize();- Y3 d5 M7 k/ @1 J6 R
8. System.out.println(init.x);
; ]) D. V" z) I6 m% V9. }, B6 g( T5 F, _9 u% l0 o8 W, J
10. }# a0 L! u# q$ A5 b$ @3 z' o/ r
当编译和运行该类时:
& }3 a. B, c6 `% \1 N9 A* U+ mA.        程序因为第3行产生一个编译错误
( {/ o2 ~0 B8 B4 VB.        程序因为第4行产生一个运行时错误) ~/ g4 R$ Z- g* C- {( K+ I
C.        程序输出1002 W. R8 A2 q" ?
D.        程序输出200, ^  H. q# j: p4 s3 l# l) Q
14.        读程序:5 L" ~) m& m  U( w# V- e
1. public int abcd( char x) {
, [# @" _) k& |: w/ q2. if ( x <= 'M' ) {
3 p  _2 ?; o$ Z2 G1 [% J: H3. if ( x == 'D') 2 ?1 s+ I; S7 E' K" k& t: Q
4. return 2;
+ l8 q$ s7 ?  y: P3 }5. return 1;; L5 _+ Q$ |$ ?  M% o5 `1 ?
6. }) X: D2 K3 D0 ^0 G- u
7. else if( x == 'S') return 3;% J' o! {% C; ~! B5 U# [, a
8. else if( x == 'U') return 4;6 H' `7 Q6 p! a1 S7 e* z' k
9. return 0;' M. u3 I- B5 ]& ?3 l' y
10. }
8 w8 V: u* C. G, R9 w* \在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
7 @. T+ A7 k3 Q$ c8 X; S3 jA.‘X’6 l% b2 p' b9 x
B. ‘A’
8 n5 P, P3 p% `- e0 H2 R# _C.‘D’; n) N( ~  T1 ]) J+ J0 }6 N
D.‘Z’9 L) B) G. |- m. X5 P+ s
15.        读程序:
" q6 X5 b* ^3 L! ^; W, T) m1. class TryTest {
6 T: ?  v5 f& v1 t2 ?" X2. public static void main(String[] args) {, n8 [' \7 ], m8 r% H4 [6 e- E- U
3. try{
  |7 Y  Y! G0 x+ s* a- r% l4. System.exit(0);
+ X! R5 k+ u& j  H6 c0 Y! m/ {3 I5. }
, R3 U6 s. s% _' {$ }4 _9 F) e6. finally {
) V! d6 Z" U* F. B8 w7. System.out.println("Finally");& w" G, }- d; _6 |
8. }
, L4 {/ Z( R- U- a9. }
" s* B9 D! R8 ^2 @% t3 h10. }7 `( H" N  [" d% y- W
当编译和运行该类时,将:8 L4 T8 m+ k+ x
A.程序因为第4行出现编译错误, f1 `0 [, e* H( k" d# [8 |. ]
B.程序因为第4行出现运行时错误
4 d: f: T- [9 T& E' D% rC.程序因为第6行出现编译错误$ Y( \$ x: |$ D2 |
D.程序因为第6行出现运行时错误/ c% [' b8 {) x' L8 M5 b
E.程序输出“Finally”
5 z4 f5 M3 m7 N% x6 |6 iF.程序可以运行,但什么也不打印
9 b1 U0 w# u3 F: M; s8 j
1 @  F0 `/ m$ z7 g16.        Given the following variable declarations:4 d- O5 f; A3 A6 ^
Boolean b1 = new Boolean(true);# @* c8 k/ ]- Y
Boolean b2 = new Boolean(true);0 ^0 o6 T- }. l$ b! ^$ k
Which expression is a legal Java expression that returns true? $ j; G* \% r6 P- t, W4 m/ u
A.        b1==b2  {# y# l) j# I) t2 l# l
B.        b1.equals(b2); t' L: U7 `( X3 ?8 n4 r
C.        b1&&b2
/ F* n& K( O: @. G. t2 ]# F& Z+ YD.        b1||b2$ A7 h: \2 o' E9 m/ S
E.        b1&b2
' z1 q8 p: U* `; p& oF.        b1|b2
1 y# d' j& z; d( B9 d! o17.        Given:
% I6 r# f: g, R1. public class Employee {' \& d1 ^8 \% H- _' m$ ~+ G
2. 1 v! J0 ]/ U1 e+ D; ?2 A3 I
3. }6 l2 M8 i2 P1 \7 r9 d
4.
$ }& C! W3 ?7 P! ^! z5. class Manager  extends Employee{" t) L, }6 x/ Q+ t. l
6. }
6 Y: H" {3 V, m1 hWhat is the relationship between Employee and the Manager?; X, w  `) ?/ z: R# y
A.        has a2 C$ _: w1 F! i0 ^3 y
B.        is a
$ b6 R1 ~: o! K; r4 ~C.        both has a and is a: a8 T3 t) D; R" p$ l
D.        neither has a nor is a
/ x4 _1 [) F/ y" ^; p" |18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
8 k2 m# V" @: I6 F  n& y0 T* NA.        BorderLayout1 d. Y5 E1 f4 `% W# V
B.        FlowLayout4 A% o& ]* G9 {: P) y
C.        CardLayout4 n0 c  V; @; j9 O9 {8 y: X
D.        GridLayout+ j/ D6 c6 O; n8 c2 ?" t  j  k" t, G
19.        Which of the following AWT components can generate an ActionEvent?
* A/ l2 N( `3 e* v* mA.        java.awt.Button  G( w5 D) }  h8 u+ c9 C6 x
B.        java.awt.Panel+ N( d0 B5 }1 ?% c% c8 J
C.        java.awt.Canvas" ]3 o# N7 N7 q% ^' E7 X$ x* M
D.        java.awt.Scrollbar
% M' Y% v7 i1 V$ k* O" F20.        What kind of Stream is the System.out object?) o& L. g- E4 Y' }* |
A.        java.io.PrintStream
( |- D" \. M6 mB.        java.io.TerminalStream
" X0 }7 D  Y5 y. H- o  ~C.        java.io.FileWriter8 k6 z$ h5 b3 ?9 @' u3 v% ^4 W( g! c
D.        java.io.FileWriter
3 ], J+ X1 ?4 e: S21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)9 {2 ?9 ?4 [9 h+ k# D( R, Q( c' y
A.        java.awt.event.FocusEvent
$ n( V$ w3 C+ m/ Y* J! NB.        java.awt.event.KeyEvent
, ]% |; _/ @$ c' F2 _C.        java.awt.event.ItemEvent
8 W- R; s2 u+ f" v3 l! rD.        java.awt.event.ActionEvent
6 a! O4 E4 H% z- x$ E, j22.        Which of the following methods are static methods of the Thread class?(双选). T3 `+ ?, S, ~
A.        sleep(ling time)! h+ r( ~' E$ n1 [5 X9 E2 W! J8 b1 y
B.        yield()! w+ }' T/ f9 _( b, I% g
C.        wait()( g3 {! }1 k/ O
D.        notify()
( e9 Y7 P8 R* E% n8 d. p1 |3 c& I23.        Which method do you have to define if you implement the Runnable interface?  M4 ?' G% r# ~4 H2 ~
A.        run()% m6 F# ~2 w% y  Z- Z) Y! {
B.        runnable()
$ h) [3 K' m% N4 ^+ N; c$ kC.        start()% R6 c* r  ^7 u
D.        init()# V7 }/ x6 \$ o1 Z; k) B2 R
E.        main()$ A/ ^; w# Q5 g* g  D
24.        Given:! D3 R& u3 `, W. M
1. class MyThread extends Thread {. n. C$ z" r9 b7 f8 P- y
2.
: X1 s' h: n: d! m3. public static void main(String [] args) {
- T! W$ d0 l9 ?! P4. MyThread t = new MyThread();/ V- f2 Y% b& T7 W5 r
5. t.run();7 c- ^7 @; C  e4 m' k. P6 n
6. }' I5 \7 W2 g; `
7. $ D) r# w$ o6 g% g3 U
8. public void run() {
% O9 J% J$ D; Y( a1 W' c9. for(int i=1 ; i<3 ; ++i) {
  {: }$ ^: j8 y3 ?10. System.out.print(i + "..");
1 }9 Z3 l( B! e: U% V8 s5 C! a% h4 Z11. }: {1 R) M, F0 x  `  @" ~
12. }
6 ?9 a% R' s6 ~2 o' b13. }
5 I1 P) e7 U# c. j! zWhat is the result of this code?C
$ _! L' B$ j# D, ]A.        This code will not compile due to line 4. D4 k. z6 B, o+ q  t2 ^
B.        This code will not compile due to line 55 {) N, F$ ^7 H
C.        1..2..# b+ p: p& O' e* \" D+ A: C+ y
D.        1..2..3..5 a; X2 }& C) u) \, G
25.        Given a local inner class defined inside a method code block, which of the following statements is correct?
9 Z; D* e* ]! rA.        Any variables declared locally within the method can be accessed by the inner class" A, A. {+ f4 j% x4 S2 j; ^/ o) t
B.        Only static variables in the enclosing class can be accessed by the inner class- t$ z; c9 ]5 g
C.        Only local variables declared final can be accessed by the inner class
3 v5 v+ U# t1 x/ x3 ID.        Only static variables declared locally can be accessed by the inner class.4 e" w7 ^2 e) D8 \/ s5 H

7 @: q# g# d( W) p. x
7 R0 w( L- r" S, a' w9 W( m
% X0 ~8 W* E! @, W& Q3 ]: {26.public class SychTest{ $ Q- e+ z- ~0 s! n% H2 X
   private int x;
6 f; E( l$ a/ S% J' ~   private int y;
* g$ K; v1 ~; G; F& b" L. }   public void setX(int i){ x=i;}
+ S" ^0 L5 C* X6 R6 K   public void setY(int i){y=i;} & U* H' n/ i0 t6 F
   public Synchronized void setXY(int i){
6 L! r6 x' r8 }  M" r% U     setX(i);
& d0 {- [8 \$ s6 t9 A     setY(i);
: i! E$ n& {2 J, Z$ S   } , a3 o, u; S- ?2 Z3 |
   public Synchronized boolean check(){
$ j  C4 N9 I0 t$ z3 g. X        return x!=y;   
4 ~, P7 U2 M# p1 r( d   }
5 V; I- P6 y; ^1 d; M5 L! F   }
/ P0 L% \0 D6 |$ U, c( G( w/ ~    Under which conditions will  check() return true when called from a different class?
0 w# r/ u0 y" z1 D   A.check() can never return true.
0 y& m: F* l- v   B.check() can return true when setXY is callled by multiple threads.
" M3 X/ n7 @5 Z   C.check() can return true when multiple threads call setX and setY separately.
: S1 u/ Q+ F9 ^! z7 o   D.check() can only return true if SychTest is changed allow x and y to be set separately.
- ~$ b0 Q) Z: L9 v5 e4 ]7 Y: W- r# N1 w" U& m8 N
27. 1)public class X implements Runnable{
# [- m2 u* M* k* r$ v6 Q) f  2)private int x; , H+ L7 x8 l2 S% W
  3)private int y; # {) R$ ]! m0 C- z
  4)public static void main(String[] args){
! U0 ]/ k9 [9 y  5)   X that =new X(); 9 _  S# `% L! Z* P2 L0 w
  6) (new Thread(that)).start();
2 ~; ^; B; b2 \  S+ _  7) (new Thread(that)).start(); : N: I% g3 d( l) W
   }
" v1 v  o2 m, l2 T/ T2 q4 Z  9) public synchronized void run(){ 4 I, d4 k; I* [* o
  10)  for(;;){   w0 p6 S$ d+ ?9 g1 n
  11)      x++; - v5 X4 l+ j. [. n9 s( ^5 x
  12)      Y++; 0 u2 ~. B: s/ H8 Z+ g# d$ Y
  13) System.out.println("x="+x+",y="+y); ; w. Q$ V% I! y' A$ ]/ k# H1 t
  14)    }
0 Z8 Z: `- I1 I( S  15)   }
3 w+ l& f" F2 E/ W8 P  16)  }   * P$ z$ A. M: Z1 Q
    what is the result?
. w9 ]! A& b& B* s" w$ K/ \7 l  A.compile error at line 6 0 V1 e$ [4 ~2 ?; c' D) U
  B.the program prints pairs of values for x and y that are
9 W6 M- n5 G2 v    always the same on the same time
" M2 _. ?# M6 z/ t! D
: [# p! Q' S( m, I2 [6 Q28.class A implements Runnable{
% C, s4 W8 ^! O8 d  int i; : M* m: j! t, \6 b, x& g/ G
  public void run(){ 3 [+ ?7 L; n: b0 `. o/ g
   try{   R$ X. s  O% X) w) K: i, l# ]; x
       Thread.sleep(5000);
  `8 O. J- H8 h        i=10;
% t0 c" m$ b7 e# U! s# u# ~& V       }catch(InterruptException e){} 1 e! m  b; I1 b. H- p
       }
1 K" v6 o7 q, x! R       } $ c: N- H; B' W' v/ L; @: z1 m9 v- e
   public static void main(String[] args){
" F1 g% j/ L; R  P, j4 X/ D6 V      try{
$ n$ L* C. t' c( U4 c         A a=new A(); 8 ~3 v% D9 Y  i
         Thread t=new Thread(a);
# m5 \" w5 ?2 D5 _' G/ E9 j         t.start(); $ D8 e1 U1 Y% s
  17) . }  y3 S  |& T/ ]
      int j=a.i; 4 w" [& Q4 X  C' N7 D
  19)
( Z9 q& l' d, \7 k# N5 @, ^* ]5 P      }catch(Exception e){}
7 x2 e4 I' |2 W      }
1 {) x6 Z1 \) N1 p, K' O      } ( n, v2 R7 l# t6 K% q* H
  what be added at line line 17, ensure j=10 at line 19?
  R, \5 B( w% L2 f2 A  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   ( _4 F/ s: X/ p& R( S( s; p: x0 I
  E.t.notify();  F.  a.notify(); G.t.interrupt(); + J8 X0 S' Y3 |/ y4 I) s9 f
29.1)public class X{
- m  j0 J) I" a* q+ z  2)    public static void main(String[] args){
# Z' g3 g+ g- p' t+ b( H- }* M  3)     String foo="ABCDE";
3 E) r# d: u6 e8 I* Y. X  o, p9 O  4)     foo.substring(3);
' a  y" w3 {1 Q1 ~9 o& ~( W  5)     foo.concat("XYZ"); 9 Q4 `8 u$ U, |" H  F
  6)    } $ z0 h4 [7 ]0 \. z' v
  7)   }
3 n# V/ N8 y9 x8 q0 F  what is the value of foo at line 6?
/ g. u( u# {, r1 J30.  public class Test{
5 U3 n8 y% [$ a  i, R% ^7 Q   public static void main(String[] args){ , x" L3 B. H6 x6 r2 a4 ]  X# m! V8 M4 W
   StringBuffer a=new StringBuffer("A"); 1 N6 z* Z& ?, q# U
   StringBuffer b=new StringBuffer("B"); 7 H7 l8 C% V1 d4 Z( e2 }
   operate(a,b); ' `  b, Q, r: p/ n6 i
   System.out.pintln(a+","+b); 0 I5 v$ x& `1 ^* }& [
    }
% k7 W9 Z6 {$ Z2 y, l2 q: p; A   public static void operate(StringBuffer x, StringBuffer y){ ( v# b- t2 M  V0 n  I
    x.append(y);
: s$ q  q; `( x7 J+ t% q2 n0 |    y=x;
+ U, G0 U( B  f0 R   }
4 P$ W  l; {4 r: X  C- B   }
" |) i" D, l, W. {   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享
' x  Y  x7 E4 P+ {. h; J& W7 j4 ^* w我已下载。。。。。! k* Y$ i6 c% @( S% N0 M
特感谢您的大公无私
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-5-25 00:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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