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

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

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

方联scjp权威考题

[复制链接]
javalea 该用户已被删除
发表于 2005-3-19 18:54:17 | 显示全部楼层 |阅读模式
Sample TextJava培训考题
  s& s. N0 m5 ?  l1.        给出以下程序:
5 Y9 R2 d% X$ K1. public class Colors {& {! L& S, A9 i: D/ Y" E) h$ W
2. public static void main(String args[]) {
; O+ }( G6 V, j0 F: s3. int n = 1;
- e' \1 Z: a2 ~7 U4. System.out.println("The Color is " + args[n]);
  J6 Z7 f# V+ C6 W5 {' o5. }
8 t8 p. j: }6 j7 }& X& `- s8 O6. }
. T# E) O- c) F3 V假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
9 f6 ?  @4 {9 r% C) V/ \A.        Colors red green blue yellow& [. X+ o! A# X9 p% L
B.        java Colors blue green red yellow/ F! d0 K) s; }7 f
C.        java Colors green blue red yellow
2 {- ]# G, R% n; D8 dD.        java Colors.class blue green red yellow
8 ?# P# j6 G2 m2 SE.        java Colors.class green blue red yellow
  Z& D' A" v: G) Z2.        读程序:
4 d0 B' `- K# H$ c$ ?& e7 v1. public class Test{
5 ~0 T1 g! k; P! F5 B4 B2. public static void main(String args[]){' P9 O0 Y, w, n0 q' v, ]
3. char c = '\u0009';7 Z% ~/ s% ~7 Q3 V
4. if( c == 0x0009L)
- u8 f- _! ?0 u) x- i/ P5. System.out.println("Equal");
5 y6 q1 c9 D5 X/ P* ?6. else System.out.println("Not Equal");
9 S7 G, H; l1 A  H8 i7. }. a  T& x! T* \' N$ f( w" O
8. }- p% m2 |- A2 ~# L
当编译和运行该类时,将会发生什么:6 c# K& J' d0 |9 Z
A.        程序因为第4行将出现一个编译错误: H% {4 r' M& X# ^3 V% \
B.        程序因为第4行将出现一个运行错误2 i4 t( J9 I- W; d" c1 A% I# u3 J
C.        程序因为第3行将出现一个编译错) [4 A; K7 t# U" u
D.        程序输出”Equal"
9 K- J% R2 c/ KE.        程序输出"Not Equal”2 z  G; |8 [& c" V
3.        读程序:+ g6 o9 A8 h* ?+ p9 I5 \9 n7 _% l
1. public class StrEq{
% E! c" K% u4 u1 X2 `2. private StrEq(){
& J3 ]1 [# s( Q: ]! o6 K4 U8 n3. String s = "Bob";- }; c, ~6 G4 j( i% {( N
4. String s2 = new String("Bob");: Z/ @( F! O: @, J- k, j
5. if(s == s2){
9 @8 I, D9 h' n6. System.out.println("Equal");
4 C6 q; P' ?8 O( }+ T7. }
& U1 k$ s' M0 e7 J, @8. else{
- s4 j% Q' Y) c! H) d9. System.out.println("Not equal");: I/ J, x  z+ }1 g  @6 Y, U
10. }- r2 d- P+ d4 ?9 z( _
11. }, X% p  i# ]0 W3 w# O* }* z
12. public static void main(String args[]){
* ^$ c% I+ A- P2 e. g- O- y2 @, n13. StrEq s = new StrEq();5 `" f- [1 [3 C2 F
14. }
- M2 S% N5 V( i& ]/ ~2 ^15. }  T& B% q; t2 O- N0 t1 T( d" N1 _$ G
当编译和运行该类时,将会发生什么:, Y' T/ f* Z" B, C- l
A.        程序能够编译,并且输出“Equal”
' p) i: G( H# e. gB.        程序能够编译,并且输出“Not equal”
: e/ {' Y) q0 V4 sC.        程序因为第2行导致一个运行时错误* V; x+ l  H2 E$ w
D.        程序因为第2行导致一个编译错误
: K  Z9 w1 I6 q: w9 Y3 W, O4.        以下那个赋值是非法的:. S* k: S0 s9 g! ~4 e: R
A.        long  test = 012;7 L! ?+ C8 `- B8 C7 b1 e  t- w$ O7 W
B.        float  b = -412;/ Q4 S' p# Y. w* l
C.        int other = (int )true;
$ ^5 _' v. v7 J+ ^D.        double d = 0x12345678;
4 I8 S/ q0 c) E8 XE.        short   s = 10;
: P. L* O  {7 T& y" \. f5.        读程序:
# X" s/ f4 t0 a  x" @" z1. class CompareString{9 g& A5 X  g7 P! ]& ?) D  M% s
2. public static void main(String[] args) {
  d/ r* ?7 u( Q  J2 s- Y3. Integer x = new Integer(5);) [4 w3 g) c0 R/ t
4. Integer y = new Integer(5);
& _+ D; ?5 L; Z0 V' L5. Integer z = x;; n! q8 i6 G2 D: w9 ?) T+ b
6. if ( ______ )3 f3 b& a0 ]) D. i" }
7. System.out.println("true");" ]; i  e7 }  s2 _! X0 P
8. }
+ `0 z, f& U# I2 u1 S. Y9. }% }/ R4 R" i; g% S
以下哪个选项填入第6行后,不能输出true:
# N1 _3 p& l  ~A.        x==z
+ r7 s6 N% R4 e4 b; H  z2 yB.        x==y' a  }' R; z* H- K& [' r
C.        y.equals(z)1 H3 Z3 x6 F# h- c1 f
D.        x.equals(y)7 F" c- y1 i5 V: r
6.        读程序(双选):8 ^! ~1 g0 q1 [0 ^( ^1 M/ u
1. public class Declare {
  }8 A  y$ R5 U0 R8 s2.+ b. l" F9 \0 R! Z: z" F$ q( u! b
3. public static void main(String [] args) {% r" c3 c% `3 A' j
4.
2 c' T9 D  i: Q  c' C5. System.out.println("The variable is " + x);) b2 ?- J  c1 S' S/ [6 Q
6. }' D/ b  q$ y& u, X; B/ ?2 f7 E7 }
7. }
: `- ?& `- }8 n! y7 e+ N以下哪个选项中的代码可以使程序编译通过6 x2 A* h. ?( O) q
A.        把“int x;”放在程序的第2行/ T# c2 O$ n0 J$ n
B.        把“int x;”放在程序的第4行6 I! g: ^( }, y
C.        把“int x=5;”放在程序的第2行
: {8 t% C, F$ x; t" ND.        把“int x=5;”放在程序的第4行
$ e! J/ J/ Y- D* K4 R( UE.        把“static int x;”放在程序的第2行
' r6 Q; e7 r( ]( X" l! f1 W
2 y7 [) S7 L/ ~' R8 L8 a/ u' F1 S0 \& k
& K1 y. l& O# r2 a
7.        读程序(双选):
2 ^% u1 K$ r5 C( T1. public class Child extends Parent{
) G8 Y. N, Y0 _2. int a, b, c;
6 |9 Y" H5 S& x+ n' L3. public Child(int x, int y) {
% L- p  a: p( }' ]# @" a4. a = x; b = y;  [; c3 q8 r5 B" M5 a
5. }
- u, y4 U" _; A2 Q) q0 @& d6. public Child(int x) {( }3 z- U1 l  _8 ]) f) E
7. super(x);
2 r* U& B& j( t; ?- d% _8. }
' ~. c$ E( N9 i: {3 S' q9 ?+ i9. }
: \9 R3 J9 R# P" r为了能使该类编译通过,下面那个构建器必须出现在父类中:
" ?% R4 v$ O1 |0 @. W( eA. public Parent(int m,int n)
! {2 K# G2 G) C/ }4 u1 N1 vB.public Parent(int m)- e6 D9 [0 q3 u, Y* a
C.public Parent()  [2 a( E0 O% z4 s7 |* m6 u
D. public Parent(int m,int n, int o)
' l4 Y; U& W  y0 Q5 [8.        读程序:
' R( j% H$ B$ K# v9 e) I) L1. public class Derive extends Base{
4 p' e# C+ e3 u- O- G2. public static void main(String argv[]){2 @; ~/ F# W' @
3. Derive a = new Derive();
; b" m# T/ x( i4. a.method2();6 A) E3 a; \* y4 k' l; i% [% V* H
5. }) j, R: N# W: z$ a
6. public void method1(){- t4 U4 P+ i" v- [8 q. l+ A2 c% T3 x
7. System.out.println("method 1");- k7 M7 l% B1 o
8. } $ c  X- ^# Y) E( Y4 H8 w
9. public void method2(){$ _3 U8 K" j6 X- S% l" s: T$ `
10. method1();
4 |( D. ~! B1 H. G/ s- w' v' y4 Q11. }
5 @- ]  G6 G( R12. }9 L/ L7 X7 V, l) `
13. abstract class Base{8 ?) J  ]7 }. D; T
14. abstract public void method1();  H! [5 d* f( N* p/ o
15. public void method3(){
9 t( m3 f, y  }16. System.out.println("method 3");5 \, j: m* T+ q8 e7 m; \( L
17. }
8 A9 p1 r7 L0 }( o; u}
  F/ p5 w: ^- a) z% p. q. E" j: n当编译和运行该类时,将出现什么:" p0 X& `( c  N  h+ b4 @* v4 g
A.        程序输出“method 1”: K( {; z2 z7 p4 x
B.        程序输出“method 3”6 B: b7 k) R, n: v, O0 d
C.        程序因为第15行而出现编译错误
4 }; D0 U1 p: A5 g' E" vD.        程序因为第15行而出现运行错误: ]# Y- K! m. M  I% a6 l. J
9.        以下哪个接口的定义是合法的:- p$ \' k+ x4 U: ?7 V
A.        public interface A {int a();}9 A- _8 B5 N( d4 S( V* w3 }) e  i! W" d
B.        public interface B implements A {}6 b4 b# x6 t& M( L" E+ r1 ]$ l
C.        interface C {int a;}
7 `+ `+ ], D* T' b# p. vD.        private interface D {}
: u: s, Y( ]9 }+ \; n" ?4 h10.        读程序:
( j0 p9 Z+ a& W/ z1. //File SuperClass.java
# r5 W" _( N' Z8 j! y2. package MyPackage;
( q6 ^5 F3 s3 r$ Y# t5 I1 U$ j3. class SuperClass{' `! v+ o3 u/ }' ^# v
4. void myMethod(){2 a" C7 F- v1 \7 m
5. System.out.println("SuperClass");
! O1 d( v; Y5 R5 b6. }# H) r# Q9 Q) O; a5 y
7. }& C  X" ]6 F4 b9 w! [, ^9 m
8. //File SubClass.java; [3 g7 L. E1 h. c/ g  S
9. public class SubClass extends SuperClass{
  n- A9 U( G4 H( ^10. public static void main(String[] args) {
& u! q% A% P" `1 w11. myMethod();
) x8 i  [, T1 G6 a/ i1 e7 l12. }( q7 p+ k0 g: v
13. }
0 a: Y- O5 m- t当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:' `3 }4 ]: z1 V
A.        两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
- ^0 j6 G0 k# d4 ?7 H5 pB.        两个类都回出现编译时错误
/ t8 u. m, f, l2 |# kC.        两个类都可以编译通过,但SubClass会在运行时出现运行时错误. i7 q) m) ?% S8 m' y
D.        SuperClass.java可以编译通过,但SunClass会出现一个编译错误2 Q4 t$ _+ c4 O; g4 D, C9 Y: V
11.        读程序:
: V6 D9 W8 k( j' j. S1. public class Test{- ]  {* V& ^/ E1 K& _7 }( L# u" c
2. public static void main(String args[]){
. G) Q" O4 {1 o; d7 }8 }3. int[] i = new int[5];# ]4 z1 R: }3 s. w9 X# |
4. System.out.println(i[5]);
2 i, W3 L* ~. J: I; b; D7 |5. }( V1 o' a6 p. [
6. }0 i  z8 C' l* w) t2 e  Z0 s, ]  K
当编译和运行该类时,会:
2 E, ^- L6 ]4 m' yA.        出现编译时错误3 }1 H8 F" g; h2 [) O7 D; j
B.        出现运行时错误3 Y# K* ~  y- c# d% P  P, N( @
C.        输出0
  e8 ?3 R& S) M9 qD.        输出null1 d" z2 J9 V% u/ X& M
12.        以下哪个选项是正确的数组声明或初始化:
# |: u4 [/ N  ?/ IA.        Array sizes = new Array(4);
. U! |7 y) N, i4 A3 d3 X% e$ LB.        double [] sizes = {1, 2, 3, 4};" g) g' k9 g* U3 _" a9 M$ R- B" z/ H
C.        int [4] sizes;
1 y# w$ ~* P, \& d$ JD.        long sizes [] = new [4] long;
) Y) g% D. ]' y( _. `13.        读程序:+ J, A- M4 t' o! H0 y1 H
1. public class Initialize{
- z: r0 P8 Z) f- Q2. int x = 200;: @' Y8 q% w- B" g: w
3. static {. q0 S/ R8 ]9 `2 j- D" X
4. int x = 100;
4 _( k( N% [* T/ U# F5. }
  @; l, ]4 p7 H, D2 j' |: a( s6. public static void main(String[] args){
2 j+ ~- c/ y$ e% S/ a3 j* F8 q7. Initialize init = new Initialize();3 {! u5 ~: r6 h# l* Z1 I
8. System.out.println(init.x);
+ O1 b6 R2 ~' v- u9. }- {. Z- E& ]& A# L! z1 k
10. }
0 O% i- y0 o4 P/ y当编译和运行该类时:! h% p3 E: L+ L# v! e5 Z& f
A.        程序因为第3行产生一个编译错误2 x% ?* G( V# Z) ]9 D& k( F
B.        程序因为第4行产生一个运行时错误" Y4 ?  r2 q  H; i  S+ g
C.        程序输出100* o& a/ l7 A' _& h
D.        程序输出200
+ ?$ h6 p. S& z' s% f14.        读程序:$ Y2 n# V5 J6 I: W5 C  z4 }
1. public int abcd( char x) {9 ]1 V9 B. W3 ^8 }) J
2. if ( x <= 'M' ) {/ J5 L! ]4 _. K) s3 T  T
3. if ( x == 'D') ) h' T8 }/ f( Q5 @) ?, J  `4 F
4. return 2;
) }& y/ E3 I2 u8 o5. return 1;8 A$ @6 ?3 _# k' |0 L5 j
6. }* ]0 a) p( b( Z; P9 m; X" e) k; U
7. else if( x == 'S') return 3;
, I7 U' I* _# u4 \' z3 x. l8. else if( x == 'U') return 4;
# [& i% _8 i% y! ]( k9. return 0;
! Y) c3 D6 A. r* U9 m6 i10. }
1 Z% J/ G# S6 C% g! T) T在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
5 R0 G6 g' a4 q3 Z! {' CA.‘X’
4 @( U* @$ h. u' a5 yB. ‘A’
. I! R; q, u8 N9 S1 PC.‘D’; d$ z3 \' Y3 A8 O' D2 G
D.‘Z’
1 Y( R2 [$ H( }3 e- k15.        读程序:# |' o$ M( n% @$ ?6 a
1. class TryTest {% z* _  }4 M: K7 P, G" `
2. public static void main(String[] args) {
" J- G- d) B1 o3. try{
1 B# T+ N1 T* Q) x6 `5 l7 Q4. System.exit(0);3 b3 m+ s& z0 l) U
5. }. m8 F' L1 _2 `+ d4 t/ L& L7 l7 p
6. finally {( y- A2 X( ^" O! u
7. System.out.println("Finally");
. n7 ~) C" p0 W0 W: N8. }
& L  y; l, K2 A& v  G9. }# i% b  O+ I$ H
10. }2 ?2 \* ^4 Q* [
当编译和运行该类时,将:9 m! C( {' q$ A1 Y0 j2 C
A.程序因为第4行出现编译错误
1 ]8 n6 e# L& JB.程序因为第4行出现运行时错误2 _! s  Y- k2 q8 v- K
C.程序因为第6行出现编译错误
: N2 }* s( t) ?1 YD.程序因为第6行出现运行时错误# o" o. R/ a2 L" a% u# _8 C3 h
E.程序输出“Finally”, S* I9 n0 S6 w1 ~0 a; z& \
F.程序可以运行,但什么也不打印4 C1 [# t: [# }( T7 i' ^( [

# ~1 F+ J" y$ u7 Y" u16.        Given the following variable declarations:
. n8 l! N( h) v2 j% o1 X% }Boolean b1 = new Boolean(true);
# x1 S/ m3 \# O) Q5 U/ u1 T0 F- HBoolean b2 = new Boolean(true);
8 k5 s  e& x* d4 E) {Which expression is a legal Java expression that returns true?
% N" M: x1 \% {8 b8 g$ W: F5 JA.        b1==b20 `2 ^+ ]7 c# R8 x5 h; ~
B.        b1.equals(b2); T+ Y' m* F1 s( q1 {1 D" I2 y: J
C.        b1&&b2
, P0 `2 ]7 w, C0 L2 uD.        b1||b2. c  n$ n# C) u: u4 A' Y' g
E.        b1&b26 Q# E6 B( V/ Q2 o- w: ?6 K
F.        b1|b2
  G2 ^+ e6 f6 ?/ ~" h9 r- m: q17.        Given: 7 y0 @$ V% P  U( j" x
1. public class Employee {
7 q' z. j' o9 ^7 l2. & }; T0 S# H9 [& b$ f# V( o" v
3. }
" R/ J# Q! Q) C1 E5 u4. 1 e' J% H" }7 j+ U  l
5. class Manager  extends Employee{
- Z& S: R' M( ]- M+ d6. }/ P# q: D4 [9 Q) R+ E. `4 a
What is the relationship between Employee and the Manager?2 }2 D7 a* A6 K$ i& e. l
A.        has a
% U+ b1 U+ G; V- L) WB.        is a
% v; X+ Q1 p- g2 l( G1 RC.        both has a and is a
2 G5 Y6 g& `0 J% KD.        neither has a nor is a/ i4 c5 x  V! h( r
18.        Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?; C; B0 m5 J6 X8 t. {
A.        BorderLayout
. L5 Z5 x1 J! P( a# x1 _7 uB.        FlowLayout$ {3 ]0 \+ f7 }
C.        CardLayout# M- y2 c% g( Z4 \- r
D.        GridLayout
6 y' a2 N! l  q. f2 w# h19.        Which of the following AWT components can generate an ActionEvent?1 |+ Q: b5 s  ~* C+ M& q
A.        java.awt.Button4 `# T# [3 U# q2 B
B.        java.awt.Panel+ B6 c9 i7 ]- u5 r$ I9 ~- |
C.        java.awt.Canvas* ^* `/ J. K, e7 t- X2 I6 f7 N
D.        java.awt.Scrollbar# x) @! l8 R; Y1 ?& _5 |
20.        What kind of Stream is the System.out object?
5 W# V8 |% j# I; A" VA.        java.io.PrintStream
+ s5 {, R+ L% q( Z6 N, E9 [B.        java.io.TerminalStream/ N& T3 a1 E  `2 @! j3 K; \, _
C.        java.io.FileWriter
9 ?# W& `8 c5 M; Q# uD.        java.io.FileWriter8 J9 F+ U7 i5 U# z4 v
21.        Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)7 l7 c8 L, E9 t0 j
A.        java.awt.event.FocusEvent6 G% {* L& ~# Z
B.        java.awt.event.KeyEvent0 ]/ v; |4 v+ Y1 q
C.        java.awt.event.ItemEvent( Q8 W; g" r; J, R7 W8 f
D.        java.awt.event.ActionEvent- V) X( o: `1 c5 G8 f/ P
22.        Which of the following methods are static methods of the Thread class?(双选)  A* J8 I2 J& g) P' n
A.        sleep(ling time)8 x) ~  T$ z6 M7 g% R
B.        yield()' ?! L- L# s. i; P( q: Z
C.        wait()
" \- \* a8 e2 v2 d! V; X% _D.        notify()
' e) U* u; ~1 ^! D/ a23.        Which method do you have to define if you implement the Runnable interface?
' s& R. o7 J) bA.        run(); e; S% }2 u6 Q1 F
B.        runnable()
% e4 Q/ c3 ~# u9 i4 C( |C.        start()
4 h6 x. ?  v# B# VD.        init()
) a7 o2 e' k8 u, z; a( C/ HE.        main()( \5 j# h7 P1 @: f! g
24.        Given:7 Q+ _, g+ b4 `0 ^/ A6 E# f
1. class MyThread extends Thread {
2 ?, D3 S# m. ^, _2.
* m1 u# |- D! ~* U* n$ o: f( m3. public static void main(String [] args) {
0 \8 r/ ~" t& a6 W' g; A. u4. MyThread t = new MyThread();
8 n0 l7 P$ A/ V- T+ u5. t.run();
* r0 E$ }0 C% W, B- f6. }
- J5 m% m& l/ T: r$ G7 ^; v7. * A, I6 g: e: ^
8. public void run() {
& |: F! T9 @+ A. s( W* e9. for(int i=1 ; i<3 ; ++i) {
5 z3 `2 x7 h8 X' F# A10. System.out.print(i + "..");
8 u, Q# P& B' `+ c0 C11. }1 q  H! u- ]( y3 N
12. }
( j) L7 H; {, O+ S+ s" W13. }
5 Q! r" f4 Q; HWhat is the result of this code?C
: W$ @2 S6 L8 `" o* l7 ^, VA.        This code will not compile due to line 4  n% I  M+ E1 n! H1 A
B.        This code will not compile due to line 58 W! Y3 ?. H9 ], ]# Q
C.        1..2..* c0 O3 w- o/ C+ l8 a- b2 U
D.        1..2..3..
; p7 S2 @% @+ c" h25.        Given a local inner class defined inside a method code block, which of the following statements is correct?
* e7 `9 g5 z. BA.        Any variables declared locally within the method can be accessed by the inner class. b; h0 @6 x" |, f7 N5 Z
B.        Only static variables in the enclosing class can be accessed by the inner class8 x/ v9 F! u# R, c) Q
C.        Only local variables declared final can be accessed by the inner class
: c1 J' c2 r' y* H8 sD.        Only static variables declared locally can be accessed by the inner class.* u) z/ a6 v) g: @0 n

, U! r# t8 J3 `6 h# O: R* s
9 z3 u, q- r) a1 {! d
  K# `: }5 m# y5 u+ Z26.public class SychTest{
1 a8 z1 \) w( |( d   private int x; & B: |( X- L0 z8 n7 m# N. Q; Y
   private int y; 4 A$ |; ]$ G6 z' Z0 B! v
   public void setX(int i){ x=i;} ! s, M; ^, Y! A$ J+ s: C& v+ k
   public void setY(int i){y=i;} $ |; e7 [4 P9 s) Z; I5 N* J
   public Synchronized void setXY(int i){ ! j, w% m& @" S/ ?
     setX(i); " c) R  X& K; u% p7 I# B
     setY(i);
8 a  E+ y: W4 ?6 U' ]  v) F8 [   } 1 S! Y3 Z* K; f( n6 t
   public Synchronized boolean check(){ : X+ R! ?( A3 X+ F' L4 O
        return x!=y;   
% T* D" k2 |5 d' k   }
; R( N- Q" _2 u9 [0 \3 ~: T   }
; |% P) u' t) K8 O    Under which conditions will  check() return true when called from a different class?
' \# j  D6 `) u   A.check() can never return true.
' y4 P' V* T0 @0 P$ \* }   B.check() can return true when setXY is callled by multiple threads.
' x( K) F  Z9 a# u   C.check() can return true when multiple threads call setX and setY separately. + x+ N1 Z5 z# ]& R; M9 ]
   D.check() can only return true if SychTest is changed allow x and y to be set separately.
( ?4 w( p, F2 q/ O" W7 X
7 Q7 ]/ s4 W/ P' B+ }: h27. 1)public class X implements Runnable{ 6 P" \  F  m) g' |2 K
  2)private int x; ; i% H; M% K! z9 g) ^- B" s
  3)private int y;
, `! k( }$ p! p) ]  4)public static void main(String[] args){ . N6 Y) ~8 x8 Y
  5)   X that =new X();
# n8 v( t5 |8 U. U  6) (new Thread(that)).start(); # x% |" x8 a$ I
  7) (new Thread(that)).start();
$ v& N4 H* U! z3 I/ C0 l! u; x   } . Q, @/ r" s# m  K9 b& @+ j
  9) public synchronized void run(){ 9 }2 ?) h6 [6 \/ r. Z
  10)  for(;;){ 0 o; y+ H) e# |- @1 i4 d' j. ~
  11)      x++; + {* l/ k4 h0 u" s
  12)      Y++; 2 m. ?, h& P! F( q, C
  13) System.out.println("x="+x+",y="+y); % D# O7 K4 _% M" P' l% S
  14)    } 8 k# X! `) H: c, h9 q
  15)   }
& G8 v5 ?" S- Z3 }; \  16)  }   & r# S2 d! y5 n) I
    what is the result?
6 ~  H; ?" \+ @8 ]" E+ [  A.compile error at line 6
# m8 A5 H& e% b( ~  B.the program prints pairs of values for x and y that are 2 X/ ]( H4 }3 F8 c9 k2 u1 G/ \% ~
    always the same on the same time 0 O7 h' h  ~4 M" U9 p- T

& Y5 ~# T: C$ G  L1 N* \7 Z28.class A implements Runnable{ ) H+ e* j/ g8 x5 l
  int i;
  `" W% W1 t3 r/ |( w( Z$ m! p3 T0 y  public void run(){ 1 W( q) R6 m5 g; h( d+ r
   try{ : x1 Y( o" g! i4 L
       Thread.sleep(5000);
8 p0 X! I- }& p4 H        i=10;   }9 A% ^. y& b3 M
       }catch(InterruptException e){} 2 m+ p: V5 L1 R# C
       }
4 s- i% ^: m2 x1 H. d* _3 Z       }
3 S# h$ r6 o$ T" F! Z+ p   public static void main(String[] args){
, S8 v: z! K  w      try{ 6 `" S6 c: J" w  `. a1 H& ]% g+ s
         A a=new A();
3 P2 Y# J# P; Z* u         Thread t=new Thread(a);
: A+ n' }/ c& E8 {0 S  s         t.start(); . B( e" ~# |2 n
  17) 9 I, C  o/ R3 s7 p3 U/ q/ _
      int j=a.i;
8 o- m/ g' ~# ]5 Q) H  19)
+ z: U; F& }0 v      }catch(Exception e){}   m1 z( s( }- i
      }
+ t, U( I- }4 y: D) _      } 5 O. s7 G* k, g) d2 S
  what be added at line line 17, ensure j=10 at line 19? : R( ]6 A* Z. V
  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();   " ~% z0 x8 b) @) D5 J' O4 r
  E.t.notify();  F.  a.notify(); G.t.interrupt();
5 W6 ~+ @6 V6 Y. K4 n3 p29.1)public class X{
$ l& N3 Y3 u. J; N$ A+ |0 E1 P8 [  2)    public static void main(String[] args){
3 y  Q, O) \. Q8 l8 `3 ?7 i  3)     String foo="ABCDE"; : t% f& F$ Z! Z, V& z0 `
  4)     foo.substring(3); . w, G$ y6 M3 @6 w3 v6 O
  5)     foo.concat("XYZ"); % t9 B# C" N/ p. E9 Q; Z
  6)    }
6 Y+ H( b$ P& z9 n. D4 ^8 O  7)   }
% M5 }" t, A# R- s0 D: z$ n  what is the value of foo at line 6?
* t* n  r) \( \3 f/ g30.  public class Test{ 5 M2 {& H$ _9 n  {, E' H* A
   public static void main(String[] args){ 1 F8 ]8 ^3 x7 d, z$ A2 H% w; x  m
   StringBuffer a=new StringBuffer("A"); ! h6 s0 e" w& x/ u# o8 {
   StringBuffer b=new StringBuffer("B");
3 A0 }  Z% x. |   operate(a,b); 7 u+ ~& e. q; \4 g9 b
   System.out.pintln(a+","+b);
( G) n0 E1 A! J3 [, B5 z0 H    }
% C1 X( W5 a# s+ N1 C0 S   public static void operate(StringBuffer x, StringBuffer y){ 9 U1 U$ g$ K0 Q- u
    x.append(y);
* ], O; ~+ T: L4 o# _# e    y=x;
" e, }3 y: H% Y* l" @$ y7 q   } $ L2 P3 g1 H* z" M  @
   }
( Z6 Q1 [8 g+ ]5 s5 @8 l, z7 q   what is the output?
yangyu638 该用户已被删除
发表于 2005-3-20 12:49:05 | 显示全部楼层
感谢楼主分享
# X3 i, Z6 \" W我已下载。。。。。% _3 |. i/ V8 Y3 I% @9 V* a9 O
特感谢您的大公无私
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-6-28 05:20

Powered by Discuz!

© 2001-2025 eimhe.com.

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