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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题6 H0 R3 E  I& @8 Q) q# F* U
1.        给出以下程序:
: A( l# f  `0 z) r7 k7 l1. public class Colors {
& T2 B- Z9 l$ P3 f* v8 p$ @2. public static void main(String args[]) {
  u9 q, {% r3 M$ f7 I3. int n = 1;
! g8 o8 h, G* }+ v4. System.out.println("The Color is " + args[n]);  }6 X  Y7 j1 V/ z4 p' R
5. }4 y5 b' d' P8 F% x( `3 v9 l5 a
6. }# y+ j( E& M; N3 ]3 _* [
假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
" {+ R! u1 C& v8 |5 i& G( ^: UA.        Colors red green blue yellow
8 C* u; L: k$ Q. mB.        java Colors blue green red yellow. {0 h8 S' L. i! T0 u
C.        java Colors green blue red yellow9 O+ V1 r* L; y3 Q& G. a5 s4 E; O
D.        java Colors.class blue green red yellow
* t- g- [7 |& [* dE.        java Colors.class green blue red yellow& F' h; ]' M3 |5 |' X" a
2.        读程序:
* d  _# d! O0 k/ S, i1. public class Test{
4 e' X& v8 r; \8 {2. public static void main(String args[]){* m& G; ]* ]; V8 q( B! `1 C
3. char c = '\u0009';
, m# m) M4 P4 _1 F9 _+ e0 e4. if( c == 0x0009L)
) Y3 }9 F) |5 o; c/ Y5. System.out.println("Equal");  G8 W( ^* E+ T8 T7 T
6. else System.out.println("Not Equal");
. D1 j' j9 d: H; V7. }9 d' V- i) {% e, w: X2 N; G- @
8. }
( [6 a0 ~* z4 A: F4 k+ O当编译和运行该类时,将会发生什么:
1 a7 ]. l& i3 u5 x7 yA.        程序因为第4行将出现一个编译错误
/ O0 A/ `6 ]( q) v9 SB.        程序因为第4行将出现一个运行错误* h5 e9 D: S2 S  X2 S
C.        程序因为第3行将出现一个编译错
2 v: a2 J$ o" J: tD.        程序输出”Equal"
1 H! L# R7 Y- O5 l  L6 fE.        程序输出"Not Equal”
% R9 a5 w2 e( c9 Y, `3.        读程序:
/ S& O  n! e$ @: k7 T; U5 }+ E' N. Z1. public class StrEq{6 }: j. j  y* }7 x; i( b; L$ J+ l
2. private StrEq(){
7 U2 X* t7 i8 B; ^) J3. String s = "Bob";
/ f, ^+ V9 L6 F, Z0 h4. String s2 = new String("Bob");
* O4 r5 s" j3 l/ K. A1 i% c5. if(s == s2){
9 S: z2 q- S: v+ J) E% l( q2 I6. System.out.println("Equal");1 |8 F1 U% |' h: z9 J; T4 p& m2 e
7. }* t$ B. g) i8 w- K/ i! o1 b
8. else{
5 ], {0 u9 P& K8 S$ B7 U) p' y! g" F9. System.out.println("Not equal");: W  }; B5 c* W# g! B
10. }
0 ^( I0 j9 [/ `/ X6 \) \11. }
* x: C* x# z) g12. public static void main(String args[]){
$ I8 Q- ?6 Y$ A4 w5 }13. StrEq s = new StrEq();
9 }8 O* ^% U7 X' z0 O14. }
# v. ?* \2 S, }; o& r15. }
$ E/ @, q* `7 N1 @3 [0 w1 I8 m当编译和运行该类时,将会发生什么:
$ Z- {7 Z: c4 k4 j; t* UA.        程序能够编译,并且输出“Equal”
/ e% K" O2 k2 Q# z/ V, UB.        程序能够编译,并且输出“Not equal”, B0 X; A3 g: Y( M6 A) t1 @
C.        程序因为第2行导致一个运行时错误: O) L3 _( z/ U" n
D.        程序因为第2行导致一个编译错误
7 H/ A) ]* {0 H- C4.        以下那个赋值是非法的:9 {+ M; t9 u( Y4 }3 m8 i3 f
A.        long  test = 012;
  ~6 R, ?, K; k/ DB.        float  b = -412;
9 a- e8 X$ l6 \$ FC.        int other = (int )true;& K" \3 ]3 s" [6 w8 y) u
D.        double d = 0x12345678;
% z/ f) F2 j2 v$ o2 I; X3 l( fE.        short   s = 10;
  z# _) P2 o6 n5 H( h7 n5.        读程序:
" S1 S0 g3 H: s2 p1. class CompareString{
8 D  h. b' ^( t! [$ A2 A2. public static void main(String[] args) {
2 h* q  {* f7 G! O# Q& B3. Integer x = new Integer(5);/ l/ ]( @5 J7 W) |- M8 I" J' E
4. Integer y = new Integer(5);
. t( m! B! d3 O5. Integer z = x;
" K0 u/ F4 c' z: Q# N( p2 d. Q$ V( R6. if ( ______ )! K; P$ u  l& s" \9 c
7. System.out.println("true");
! ~  g1 y/ {/ ^8. }
+ K$ W+ w* G- B% ]) M9. }
( _) `& P: W6 u9 t/ L以下哪个选项填入第6行后,不能输出true:
$ X5 R5 F4 W9 P" v7 ^& S5 WA.        x==z
1 Y) b- i6 @# o9 u) c  aB.        x==y4 ^) r) X/ B% I; c; f" H
C.        y.equals(z)! g( a3 e- H! v4 G  X7 g
D.        x.equals(y)
( C+ S$ ?. Q# M) r+ R* W6.        读程序(双选):
0 {+ l& m# p7 p; D  A1. public class Declare {
* E- O) }: X: t" ?" C2 b  Y0 g' ?3 \2.3 _9 f8 O6 y, G6 g
3. public static void main(String [] args) {# w' b; V  J7 u" v2 g0 n
4.9 M: m( U  b* z3 ]
5. System.out.println("The variable is " + x);
3 @3 b) X4 ~. i9 c! K$ D( X6. }, P# z* l% N7 k2 z8 q" _
7. }0 n: T# ]- v0 |$ f  _5 u- g
以下哪个选项中的代码可以使程序编译通过
9 |- P+ A( Q1 w; e, n8 S) nA.        把“int x;”放在程序的第2行
* d  ^2 m# |. {1 mB.        把“int x;”放在程序的第4行
5 c5 l9 l! s' _. F4 [' R5 y4 W) VC.        把“int x=5;”放在程序的第2行
) F( n. K5 o* Y! k, P$ i0 zD.        把“int x=5;”放在程序的第4行# [( i4 k* i) o5 G0 s: U
E.        把“static int x;”放在程序的第2行7 K1 r3 }- ]- ]

, ^" S7 d4 `3 q5 z0 |2 u% M9 g  u/ z# {4 i* e  h
( t$ |6 k: M  z+ |- |# X: ~! U& u
7.        读程序(双选):; n. o$ s! A. ^
1. public class Child extends Parent{" a3 K* W" @& i3 V
2. int a, b, c;
$ |" W+ e9 d4 b- |8 l* p2 B3. public Child(int x, int y) {4 G6 d5 J" _# b% N( l6 k
4. a = x; b = y;
' @. @, e, v& S7 }5. }* s1 P. O. }( `$ R0 B+ ]8 K
6. public Child(int x) {
- h! k/ k0 O  e) s( {7. super(x);
, o' K+ g- |* a' E& }% @5 s& `/ x8. }
1 f5 i( y- H  X0 b% F9. }! G, `  ~4 O/ o2 C2 @- E5 `
为了能使该类编译通过,下面那个构建器必须出现在父类中:
0 c# n* ?# _1 mA. public Parent(int m,int n)
, k- i% x9 X, W$ gB.public Parent(int m)4 K' t$ m8 D5 r# _2 m/ X+ c* _# R4 h
C.public Parent()
; i; G9 D$ c5 N7 x4 J& o3 R- bD. public Parent(int m,int n, int o)
0 O/ e/ k; `6 e+ T8.        读程序:" S6 s* n: P$ B( c8 x& B5 W% v
1. public class Derive extends Base{
5 @1 b3 V& |- Y& m2. public static void main(String argv[]){2 V6 A) h- }1 _9 R; Q0 K. K
3. Derive a = new Derive();
* m' L) p1 J$ R: d+ f3 ?3 W4. a.method2();0 ]. j$ y1 _- y  s
5. }
% F( E0 Q% S- y9 w6 \8 F% [6. public void method1(){7 q; n; c9 U' ^0 b2 X: G: y! }
7. System.out.println("method 1");
, g2 S, C% y, ]; Z/ [7 Z  N8. } 7 O4 ^5 D% y4 w9 [  q% M+ c/ z
9. public void method2(){
7 G2 I# @: n4 p' b- G10. method1(); 4 O/ a( |2 _) v
11. }
. C$ C0 n) i6 u( ]7 O  i3 w12. }5 ?3 w$ e  V: C6 ?( e9 J
13. abstract class Base{+ \2 I7 [8 |' A
14. abstract public void method1();
8 w# q1 d( Z, W$ w& S2 o15. public void method3(){
! @) \% E6 a7 r/ s( C5 p) w. |3 K9 K16. System.out.println("method 3");
7 j- ?3 c# w% R, A5 x4 _17. }
' |3 }: F$ N  ]& J}
4 J( l% j6 E: d7 b6 ?. ~当编译和运行该类时,将出现什么:7 d5 k6 V0 \6 w) z& D, l% r
A.        程序输出“method 1”% B$ I$ A$ ^4 v& x
B.        程序输出“method 3”
& B9 ?3 \9 T" N5 l# E! S4 q( TC.        程序因为第15行而出现编译错误
5 o' U. E% x0 O* pD.        程序因为第15行而出现运行错误7 I# f6 O: h7 j7 ^3 w" H
9.        以下哪个接口的定义是合法的:, s& L6 o7 Q/ `
A.        public interface A {int a();}. C5 E! V" ^* y" J% H
B.        public interface B implements A {}
5 ?% C( {$ ~0 ]. aC.        interface C {int a;}7 ?# Y; q9 X7 u3 U$ M* |! u9 G
D.        private interface D {}
* t. a( M; b2 p( v10.        读程序:
8 z: R1 [; ?; W: t* U" T% Y1. //File SuperClass.java
9 y; E( }- L8 H+ s8 G  @( @  F2. package MyPackage;* I, J& q1 C) @& w9 U
3. class SuperClass{8 F* _$ `# f0 {7 _" }5 \
4. void myMethod(){& K* |5 [1 Q2 ~- o+ k% i4 U
5. System.out.println("SuperClass");
: ?, _& T" u- s- b9 T# g( ^% x- H6. }
3 {, z( i: Z6 X4 l! Z/ E: Z7. }
1 p" O: _5 l" u* y/ M8. //File SubClass.java
' m" z2 f3 {2 D9. public class SubClass extends SuperClass{0 [7 e2 J8 Z* F7 @( b7 V2 S
10. public static void main(String[] args) {7 W# h$ I1 ?. d. Q; d+ m4 L9 V
11. myMethod();
0 B3 E5 n9 O' E- Q2 g0 u12. }
! D+ R% p5 Y. }; i3 H4 P13. }( B+ S. d+ m' y/ P2 U/ x# K9 d. W
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
* q1 t, P+ K( J/ i; S& @: |2 g, zA.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
( ^  b# V+ t+ ?% V" b- {B.        两个类都回出现编译时错误
$ \) \5 s6 z7 ^# ^C.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误
+ H. T* B7 ?3 [: ]! b* F( jD.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误, _7 e4 Q: M$ C& c. ]  \4 x4 B: V
11.        读程序:1 ?1 F( K* a* f
1. public class Test{- U5 W$ d/ z& a0 M
2. public static void main(String args[]){/ S0 A3 Q5 t7 ]# b( ~0 O" {
3. int[] i = new int[5];
2 L9 ?, d1 j( G7 N2 l1 n* ~4. System.out.println(i[5]);
; M4 a0 F, f+ x9 U7 r- K4 N9 `5. }
) D7 Z. U7 V, F: ^% T6 ?% J6. }' D; E0 P7 T$ ^8 a- C$ |
当编译和运行该类时,会:
% c( L$ P/ y( a- ]A.        出现编译时错误
+ d$ ?- z+ ^& J; aB.        出现运行时错误
+ Q; H/ C; ^4 T& x) v( ]& zC.        输出0$ n) O* Z/ _( t$ f2 s9 P
D.        输出null
7 N" K4 E# W: E2 S3 m& S  W12.        以下哪个选项是正确的数组声明或初始化:9 E. e$ {+ A5 v1 Y
A.        Array sizes = new Array(4);
/ S5 g6 c$ T; nB.        double [] sizes = {1, 2, 3, 4};6 x$ F2 K$ H  T' s# k8 j
C.        int [4] sizes;* F8 V. H8 ]! i9 h. a# i! A- ^# U
D.        long sizes [] = new [4] long;
# `7 @! d' N/ U" F13.        读程序:; A+ v: n- v. x: o3 s
1. public class Initialize{
% c4 l# q, {9 n1 [2 d) @2. int x = 200;
( n* `4 R7 g  T  M2 T2 e3. static {
3 a6 P8 w% Z' `( g: u4. int x = 100;
# I! K1 ~6 f. M; n6 d5. }6 G) _9 J5 M/ v. s2 B
6. public static void main(String[] args){1 q* n% q8 K0 @2 H; a+ G8 m* p
7. Initialize init = new Initialize();+ w8 k3 C  Z9 L4 G4 B
8. System.out.println(init.x);: ]& X$ i: A1 s* P
9. }
/ R4 u- ]: N+ o$ m! [# g. }5 m* I10. }0 a9 `# v. H. X+ G: W& o5 E) h+ B- z
当编译和运行该类时:% X1 h; T( j. P% K9 l
A.        程序因为第3行产生一个编译错误9 X4 u& o* [( |* Y; w8 E- M; h
B.        程序因为第4行产生一个运行时错误
+ |4 k+ A4 j+ ^. P( o9 L, K7 UC.        程序输出100
+ R- {* L  l5 ^- s' D6 F6 V% nD.        程序输出200
7 V; s) W; B1 g: S( z. Y# ?+ F14.        读程序:4 U  v) u3 I* ^
1. public int abcd( char x) {
$ e/ b% Q) o" I+ K, ?7 }2. if ( x <= 'M' ) {
3 |0 A. J' n' K( v2 x% B0 ^3. if ( x == 'D')
0 X8 U2 Y. t0 K. j4. return 2;
+ p0 ^) w+ w5 E  H7 ?5. return 1;
) x! ~/ _: V( t# V# p6. }- C( `9 q1 n% i( B
7. else if( x == 'S') return 3;
8 ]/ H, y" A. P- u  {# {8. else if( x == 'U') return 4;
' ^- |; f) N2 A* F; B6 t9. return 0;; w% H0 R; I. A$ ]/ W
10. }$ p# X2 Z) U( Z9 F. \! v
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
4 m, K4 f% M; @5 F) x6 M, TA.‘X’/ |$ E3 P% Q) |4 d
B. ‘A’( ?4 Q  h: ]& p: {, p
C.‘D’/ ?1 o# T- V# p( w# X8 p
D.‘Z’
7 b( }$ ?4 C* c: Z$ z15.        读程序:
9 J8 T8 Q! [& t: }1. class TryTest {
4 `, s  }6 I! ~2. public static void main(String[] args) {5 w5 \* S: B: p0 _3 l, t
3. try{
% S& A. |6 r2 @; ^4. System.exit(0);
' \, _& T) c$ l: b; W8 I  A- W/ I5. }; w, j, P, B- M/ R
6. finally {
  [5 W* ^! f) Q: t8 i7. System.out.println("Finally");9 B. x( \2 G+ \! J' E# U% E
8. }. c* ^' C) \6 Z: M' W
9. }
# _/ H  R$ V* I0 d% \: S1 ~10. }
. b) E. W/ X/ r: B: z. u" Y( w当编译和运行该类时,将:
3 r9 i$ h5 J. h: h& b5 TA.程序因为第4行出现编译错误
8 \* t5 G" }' v2 OB.程序因为第4行出现运行时错误& ~3 Q; X% v4 t7 ]$ O
C.程序因为第6行出现编译错误
; k+ o$ P& F$ |' ^- _D.程序因为第6行出现运行时错误
5 ~4 |: A0 |. J3 F: zE.程序输出“Finally”
8 Q9 @1 {1 _5 X+ \' s) YF.程序可以运行,但什么也不打印& K: A2 G* {8 L" K- n

$ D6 T. \2 I- `! p& g3 C$ w16.        Given the following variable declarations:
' ~) c  |7 a- l: VBoolean b1 = new Boolean(true);+ m& d& A. b$ ~; ]* ]
Boolean b2 = new Boolean(true);  W# `3 c$ y" M2 Z5 W$ Q
Which expression is a legal Java expression that returns true?
& u; s+ Z4 X" d' OA.        b1==b2- \, J0 @% D# W. S7 _6 O) V
B.        b1.equals(b2)' M4 r$ m- T, A* ]- H6 @  B
C.        b1&&b2
- L8 k2 _# H( t, e. mD.        b1||b2& V6 ~5 X# Y5 Z: N2 V3 B
E.        b1&b2
8 P* A+ M7 ^, P- NF.        b1|b2
; h/ D0 Y  a) p( D5 N. j7 }17.        Given:
, P: h7 V4 W$ {4 l, L% Q/ Q  M  {1. public class Employee {
1 t/ r" h# q7 i- e0 s# F2. 1 M8 X( A$ D6 H. ^5 B
3. }
5 c" A! y' G, z' _4.
1 ?1 W2 j+ i( b" ~) z9 h, t+ ^* i5. class Manager  extends Employee{
1 ^$ b) |0 q% L* b' c4 O6. }
2 x: C6 \$ f& v, a: ZWhat is the relationship between Employee and the Manager?
* L* v% o, H/ H, z9 E" ~) M! H2 G& BA.        has a; [, f& L: i1 Z) ]2 G0 B
B.        is a* \9 }& h; X1 h7 w. k  W( w
C.        both has a and is a
, o+ p5 x, k1 o# r" u$ G3 P8 U# X9 \D.        neither has a nor is a
( P) K+ _. h; X3 l- o18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
4 m: `  l1 [% S" LA.        BorderLayout3 A2 ?+ ~7 e9 T0 D3 a
B.        FlowLayout
7 ?6 y3 o( G3 k% `C.        CardLayout$ c# U6 T7 J) m5 K
D.        GridLayout
6 _) H8 N7 [2 }! Z3 [19.        Which of the following AWT components can generate an ActionEvent?
- f7 d- j; ]4 C' X: V- lA.        java.awt.Button' {# E# X7 p) s# L5 J  {6 m0 H0 C
B.        java.awt.Panel+ h0 i: b. o5 m8 P: P$ S# Y2 i
C.        java.awt.Canvas
* C' d+ f* s& kD.        java.awt.Scrollbar$ A8 X5 n: p2 @7 `' I. ?& m, ~
20.        What kind of Stream is the System.out object?+ W, Q( z# q! O1 L1 Y2 }) @
A.        java.io.PrintStream" `$ l' y  x. |0 m& Y
B.        java.io.TerminalStream
" {+ K# q+ s9 P; C6 H6 }C.        java.io.FileWriter5 P  H9 C8 P* D. Z( n
D.        java.io.FileWriter
1 J5 M4 L( `' K( ]21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)
% d5 q/ x( G4 g& O% @9 v# _5 h0 i/ qA.        java.awt.event.FocusEvent
$ e3 ^) ~$ s4 s: PB.        java.awt.event.KeyEvent5 c3 M$ d7 ]6 T0 n3 _9 R- n6 v
C.        java.awt.event.ItemEvent
2 j4 ~6 Z( }4 Z# W- \( _D.        java.awt.event.ActionEvent6 W! Q/ Q. u7 I; O4 Q
22.        Which of the following methods are static methods of the Thread class?(双选)
+ q% ]  @$ }% G4 gA.        sleep(ling time)
% w! `1 m4 Y: D9 v4 E* ]+ `B.        yield()
, d$ d7 D; H. f! p' J8 Q+ d) H5 Z2 hC.        wait()( t+ L* S  m/ @- E$ S/ G9 T1 }% q) V1 F
D.        notify()
$ }' K' v( J) z( i23.        Which method do you have to define if you implement the Runnable interface?
0 h7 |/ J8 D  F+ wA.        run()
! h5 P& n0 u& |B.        runnable()
( O6 E! M" L0 P# S9 w8 nC.        start()
* z# W% d  ~' H# D; q) F% [8 }D.        init()
- }& _9 g3 P3 X6 f4 b) ME.        main()
  V! d9 u) X+ z24.        Given:
; s0 i9 ?  B$ ]# S# d3 V" i* y' f1. class MyThread extends Thread {6 P: A$ r$ K/ P0 g! a
2. 7 k4 h. T. B, l) ?* ]9 J' w( r
3. public static void main(String [] args) {$ v1 V  i- S- l% T. J6 ~$ W: h+ i
4. MyThread t = new MyThread();
: X" E; J; \& A% \" A7 k9 c, ?5. t.run();5 w( B5 a! r" H8 D& }' K) O
6. }/ z! S8 W" h$ T6 \
7. " x- M4 B" z6 T8 n' s/ B0 G$ C% Y
8. public void run() {& m2 A% G& k" `6 B, d) J# N2 |
9. for(int i=1 ; i<3 ; ++i) {5 L7 \% v3 W3 T: F
10. System.out.print(i + "..");4 W3 t3 V9 k. }
11. }
9 y: x# \% h. |+ B) d, y12. }
' K' M2 t8 D( T13. }
: ]8 z; I! W6 X/ Q$ E5 |- t6 bWhat is the result of this code?C9 L% m: Q; Q6 D( l
A.        This code will not compile due to line 4
; @% [4 U, @+ s- a0 n! ?B.        This code will not compile due to line 5
/ z0 ~/ l, c+ }% X# AC.        1..2..& o7 K' G* c7 U; s
D.        1..2..3..: C8 h& p6 V; o. o1 a) @" T( u8 s
25.        Given a local inner class defined inside a method code block, which of the following statements is correct?
; z- [% m* A* D3 M: H7 sA.        Any variables declared locally within the method can be accessed by the inner class
6 X, D6 ~' N- g# T! gB.        Only static variables in the enclosing class can be accessed by the inner class4 j- f6 p0 ?, Z1 _% I) n
C.        Only local variables declared final can be accessed by the inner class
, X# C) S3 V5 ID.        Only static variables declared locally can be accessed by the inner class.3 W( T. X% u2 ~5 `* E; |

" o, q) ?6 [: R& V/ I/ g( ]
% z4 ?" G1 e5 P7 A: |6 r" w
/ I7 S1 v/ @9 K26.public class SychTest{ 7 }+ d) q! K5 H7 O6 |+ D4 B& Z% F
   private int x; & A. a% ]+ p8 I& V; i
   private int y;
1 C5 A. a& F) z6 d   public void setX(int i){ x=i;}   M+ i5 U! f- a0 ^* l  F7 ?
   public void setY(int i){y=i;}
- i; Z! i. T4 I- p% B) c   public Synchronized void setXY(int i){ * ^" V# j+ ], p5 y4 ?- ~5 y, Z' q
     setX(i); 9 `  f- \7 I. |4 }( K
     setY(i); & p4 O" _4 m! ^% v& T, t
   } / w+ l: J* \' k6 I+ X- J
   public Synchronized boolean check(){ 4 y" t4 e/ S( g$ O0 a$ P
        return x!=y;   
- R! z; |! ~6 r" E   }
: G" H- s% H+ ^" q$ l9 v; h4 o   } 9 k- ]) y8 p  k7 ]( [; V) K0 q9 D
    Under which conditions will  check() return true when called from a different class? 2 M+ M" r) Q; y+ D4 L# x
   A.check() can never return true.
' Z7 M: O/ J9 x5 R. |" _   B.check() can return true when setXY is callled by multiple threads.
% [' l* q& a# P8 E) C$ f7 ~5 b& G* f   C.check() can return true when multiple threads call setX and setY separately.
& d  A3 y4 D8 Z: w; l8 y( i, g7 G, C   D.check() can only return true if SychTest is changed allow x and y to be set separately.
3 \7 w" |3 x- S: s# T* J0 m
) ^5 B% J# i) t) l9 S8 A27. 1)public class X implements Runnable{ 5 y- W' U  C6 X
  2)private int x;
" w  }9 L  Q6 D- H2 A" P3 m  3)private int y; 4 s( M$ x0 P' X9 Z- \: l; ]3 D
  4)public static void main(String[] args){ - t$ L( k+ P% }! w) J' S
  5)   X that =new X(); ( L: }  O  V5 d* l; i" G9 q
  6) (new Thread(that)).start();
/ v' v, A9 P  `- [# F4 l4 x, ]1 Q0 R  7) (new Thread(that)).start(); 8 ]+ H% v. E$ _$ G* }
   } 9 i& ~, i; i# G4 i% N+ R
  9) public synchronized void run(){   a4 x4 m# m. G7 r+ I9 i
  10)  for(;;){ 4 _! D7 e; h$ b2 I/ X$ {7 [7 {
  11)      x++;
& D. Z) R" Y2 J4 q# `3 R  12)      Y++;
) h: l$ I: m7 M- E  13) System.out.println("x="+x+",y="+y);
" ^7 c1 j0 m: p5 i  14)    }
& A$ b/ I- C$ C- V) J  15)   } " x, H( c. d6 d- N
  16)  }   + _0 T5 q2 w$ A. Q, }
    what is the result? 4 R: ~' K; N6 \1 l5 Y# e; n& t
  A.compile error at line 6 1 u. [  h. b2 e6 M6 t5 d2 K
  B.the program prints pairs of values for x and y that are 5 O  L- _+ r; D7 D' m/ `- l5 ?
    always the same on the same time 8 S( k- O$ i5 N' S8 `; L" T0 b$ F
1 t1 U% V' H' ]+ T  p) L3 `- z
28.class A implements Runnable{
9 @9 j, O5 _( i( `& b  int i; ; F4 O# }4 ?$ d) e
  public void run(){
, V) x3 M$ I" v3 n! ~$ S   try{
3 S, ?7 u# D) x5 z       Thread.sleep(5000); 0 r8 n9 \7 N" z
        i=10; # U: l3 l) n7 |4 Q8 O. R
       }catch(InterruptException e){}
7 o1 T3 [4 c$ U# L/ r2 o       }
3 ~9 }# U' c7 n" n) h: z8 |6 Y       } 9 |" w$ I+ |* i. i/ V
   public static void main(String[] args){ , O/ s. G1 s3 A
      try{ , U5 p- Q( S- |+ `
         A a=new A();
6 v5 y. d0 b5 W2 \5 F4 _  C1 g         Thread t=new Thread(a);
& [. T" o5 a9 `! d$ _         t.start();
$ T4 S) _$ j7 `% g4 Y: h  17)
0 e# K2 f0 o  B! M      int j=a.i;
3 @/ B" \2 q! a! r! q  19)
' l9 q% U$ f+ D  ^! l      }catch(Exception e){}
5 H) l. ^' _( }$ v& p      } " f9 P/ I- e- w+ u) v* ]
      } ' h- U5 \& N# t% Y: \
  what be added at line line 17, ensure j=10 at line 19?
8 O5 v8 u% M2 O% S0 [3 R  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   : o! L, c, j' f$ @1 e9 q
  E.t.notify();  F.  a.notify(); G.t.interrupt();
/ K" h  m3 l3 t. H29.1)public class X{
( q( v: V6 a+ q  u  2)    public static void main(String[] args){
3 J( \+ \; s- a8 U1 j  3)     String foo="ABCDE";
  S5 L* e. Y! u; Y  4)     foo.substring(3); , h( l- {6 E* r' j: g
  5)     foo.concat("XYZ"); : O" s; D7 I' w' C. S
  6)    }
; [  n' B$ d1 K# M4 p  7)   }
4 m0 ]8 h0 B0 p1 o  what is the value of foo at line 6?
) ?9 H/ s! m- |7 t2 T/ `30.  public class Test{ ( o  ?0 j* @2 Y* G; A9 Y
   public static void main(String[] args){ ! j3 c! ^6 h) s
   StringBuffer a=new StringBuffer("A");
3 Q! @5 g( L( }% z9 w   StringBuffer b=new StringBuffer("B"); 1 W8 A) {" Z( `! {) g/ m
   operate(a,b); 2 l1 h, f8 ^3 \0 T( z1 y# P5 I
   System.out.pintln(a+","+b);
& `+ X* H. [' V" Z! U    } & U6 ~1 D( t3 |& p0 H- I' k
   public static void operate(StringBuffer x, StringBuffer y){
3 C1 b; V' k7 s& k9 x8 D) i; M    x.append(y);
9 i* _2 [% F! Y% q& l    y=x; ! g! S4 M7 T5 _+ [
   }
4 b, ~# h: r! H   }
0 K8 R, C& u% s# G, e, L+ x   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享7 f' T, {5 ~2 h( \
我已下载。。。。。
7 H( `. u0 ~* }; c0 Z4 X  i" U/ \特感谢您的大公无私
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 02:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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