Sample TextJava培训考题
( s, I6 W0 y# A4 B0 X; q1. 给出以下程序:$ z( G( w2 g; L3 V# Y1 p& o; k
1. public class Colors {
% B6 a0 V* ~, u' {6 d2. public static void main(String args[]) {
1 u5 }8 d' L: C% b6 D3 P: [9 i. P' V3. int n = 1;/ O# V8 J8 H5 R7 t+ A) q( i- M6 ?
4. System.out.println("The Color is " + args[n]);; T, v3 b6 x& \9 b) Z" G5 X, r
5. }& H A+ _% Q" X6 k2 i% _: J+ o
6. }
3 [3 C5 T5 h3 L- v+ S假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”4 a4 j& g/ y, _6 _# O6 f
A. Colors red green blue yellow
3 h1 V# T( n' F4 d; L T7 hB. java Colors blue green red yellow
+ y/ u. ]) n, M# U/ IC. java Colors green blue red yellow
; {# e4 q. q1 ^& B# O: _3 oD. java Colors.class blue green red yellow" I; h L. Z' J9 @$ P: x. ?
E. java Colors.class green blue red yellow
! m) \5 v; {# R# |2 U' E1 e2. 读程序:+ S+ O/ N8 q- ^, c B
1. public class Test{
' v6 ^8 A; C/ v" ]2 S, w2. public static void main(String args[]){* K" P [! P6 S
3. char c = '\u0009';4 A4 {8 |, \6 f+ |
4. if( c == 0x0009L)) H% }& h6 @2 a. G. R1 t
5. System.out.println("Equal");+ }5 A% m& z) _9 W/ l, h3 j
6. else System.out.println("Not Equal");
) t3 D9 v, g) d. G' i7. }! V' y' u5 k& d( J
8. }
. ]4 ]9 r' W7 |6 |& Y; \5 Z当编译和运行该类时,将会发生什么:0 T F$ F H( G
A. 程序因为第4行将出现一个编译错误
: l6 `/ E/ ~1 Z) O8 q/ d$ F, n; q' lB. 程序因为第4行将出现一个运行错误
- F* b$ L8 L, d+ d( |C. 程序因为第3行将出现一个编译错 ?4 w& w# y5 U9 |! }
D. 程序输出”Equal"3 r& ?& N1 Q3 g% G k& P! Y# ~9 _( s
E. 程序输出"Not Equal”
/ m& Z( \5 O1 t3. 读程序:! }" s1 `" H7 P' o ?& A+ q' A }9 h H
1. public class StrEq{
- U2 n. Q& v) h, [, ]$ H2. private StrEq(){7 U# {% v; K% W) P4 [) E/ O
3. String s = "Bob";
$ d1 ?% L% M s. z) Z0 i: a4. String s2 = new String("Bob");9 d) @) W( Y9 I
5. if(s == s2){
( U6 G5 A- D& e/ Y0 y6. System.out.println("Equal");4 w7 z: ]" [; i8 ?2 _
7. }9 B. D u6 q3 }9 G- Q: r
8. else{) {. Q3 B/ W. L _8 n- d) A1 _) {0 ~
9. System.out.println("Not equal");
( N# ^' W! }0 o( b7 M* g10. }
`& d* I5 T1 p' E" \# d! M3 v1 J/ z11. }" E) z8 U7 `$ v( a6 C" Q
12. public static void main(String args[]){% i' s& g) j. l+ J. E8 s
13. StrEq s = new StrEq();4 l, Y+ V+ ~8 v1 w. [
14. }
2 _- }9 \" h, E% e1 u' A4 _5 z% Q! }15. }- _- i# u& H6 K2 e9 s s% ^
当编译和运行该类时,将会发生什么:
' d( M; T1 Y7 ^ W3 l+ RA. 程序能够编译,并且输出“Equal”
# L8 C: T! @( _0 E) zB. 程序能够编译,并且输出“Not equal”' Z6 y2 W! X0 _0 y" m3 {6 [
C. 程序因为第2行导致一个运行时错误" w. w. C) a3 H) U2 ?
D. 程序因为第2行导致一个编译错误" Y/ l$ R0 p- b+ z5 C
4. 以下那个赋值是非法的:
) \. s3 t1 {0 gA. long test = 012;
: n; ^6 ?* g( zB. float b = -412;' G( C& s, B7 k H, Y) K5 m
C. int other = (int )true;
0 j; i/ Y6 K# R$ XD. double d = 0x12345678;
; X- O8 ~8 s0 @; @E. short s = 10;# r5 j* i1 E9 E9 A( N+ T
5. 读程序:; F5 p1 [" A" \
1. class CompareString{
. A4 g6 z+ ^8 @2 L/ i7 v5 q2. public static void main(String[] args) {
F+ v3 n4 ?; L/ l3. Integer x = new Integer(5);
9 r I) F5 @. Q" `' t ]3 Y, g4. Integer y = new Integer(5);
9 B8 q* r6 \- M( f9 ~! T' U5. Integer z = x;
1 L# e+ n% {' a# }. t4 S6. if ( ______ )
( a2 t( D% ?) b7 E7. System.out.println("true");( j9 h; R, l; s1 R* m9 c# F
8. }/ k b. z- k' r1 t! r
9. }
1 Z9 R# u1 y8 L( ?8 B. L) J; E以下哪个选项填入第6行后,不能输出true:, I7 r! w$ ^1 [3 P5 O
A. x==z
8 T: P0 v- ^- g) xB. x==y$ N0 H7 ^/ v; Y( T4 ^' U
C. y.equals(z)
& W) R% B: O5 a) j. C1 v2 y2 P* q5 [D. x.equals(y)
* w/ j( F I" w1 x; y0 o2 g6. 读程序(双选):9 V" W8 \; m0 O9 j- ?3 K
1. public class Declare {: }3 S K5 f, \/ X
2.2 J! m. b0 n. ]3 P
3. public static void main(String [] args) {, l8 M! d0 Y0 B6 A; u5 a
4.3 f6 @1 p2 a0 x9 r3 L& T$ F0 K1 c
5. System.out.println("The variable is " + x);
4 ]5 T' U) b! C' j, k4 t( ?) Y6. }1 y f2 G* O, L4 f6 K
7. }% T7 {9 m: V! k
以下哪个选项中的代码可以使程序编译通过# A. k7 |. b7 m& h+ W- g [
A. 把“int x;”放在程序的第2行
, E4 i3 f( {. I8 w; U8 I9 KB. 把“int x;”放在程序的第4行
. h5 z0 x: `, i4 w0 {0 D) @C. 把“int x=5;”放在程序的第2行( p" L0 w) D/ y$ ]$ t9 O7 {
D. 把“int x=5;”放在程序的第4行
) F/ b8 t4 I3 a! lE. 把“static int x;”放在程序的第2行
9 [1 }* A% i4 [8 C& k4 o% u" q x. ?3 N# A: V
, n; v8 ~7 o7 a& v
" ^% j' |+ ~/ h) f1 f- q8 [* H1 U& R7. 读程序(双选):
2 A) e$ ]; M: a: u+ A- ]1. public class Child extends Parent{) o* l3 U( w$ W l/ u/ |' Y, H2 L5 M
2. int a, b, c; O" M/ ^* d u) b9 n, O- B
3. public Child(int x, int y) {0 O9 z+ ^0 X8 Q' L' [# \- T
4. a = x; b = y;6 Z9 P2 l# }( l# ?/ m
5. }7 N/ K4 g; O0 Q" u, ~6 u+ c
6. public Child(int x) {
9 h4 j4 x1 s5 K% ?# d8 {0 L7. super(x);
2 w" z, O4 G( ?& `# ?8. }
6 C5 z9 J1 V. M/ E9 }) Q6 G9. } i8 P, Z8 b M+ ^+ {
为了能使该类编译通过,下面那个构建器必须出现在父类中:
, B( E' ^: x& V7 q8 I$ ?+ BA. public Parent(int m,int n)
9 ]; t0 \+ \! ]1 {8 FB.public Parent(int m)) ]" k' U/ R- h$ b, w
C.public Parent()" g: S! ~. i* v& e9 C- i1 u- j6 [/ a1 p, o
D. public Parent(int m,int n, int o)
$ M: z5 t$ \5 E; `8. 读程序:) G- _: N' I9 f, A: Q$ ?
1. public class Derive extends Base{: C7 v4 i3 S6 d' d6 c% T; l
2. public static void main(String argv[]){
4 x7 d, k. k( N: N3. Derive a = new Derive();5 o) q6 _6 \+ ^, `5 V' a
4. a.method2();% Z, |+ w R0 w5 B* W& w
5. }
$ u# @" E6 i$ m6. public void method1(){. c! f6 e) i, R9 @+ V
7. System.out.println("method 1");+ F* x3 y$ V8 _
8. } ) A/ j" S& c, x5 c: I0 V
9. public void method2(){
' e$ _" s- y( E5 f5 H1 d10. method1();
. f4 f# B/ r y6 o9 ?3 @, x8 c11. }
: \- A( `5 V# g/ z; e) [# }12. }( J8 Z9 u9 m0 r8 r' n2 J; U2 h$ _8 e
13. abstract class Base{
) `) H! m3 m* J) U+ C14. abstract public void method1();
8 a7 |4 j9 Y+ e D, i8 A8 D6 P15. public void method3(){
0 r% G/ P6 }1 P: j4 o5 _16. System.out.println("method 3");
2 w" A9 Y" Q# C2 K$ r( r17. }8 n0 B0 W$ t$ ?1 R @1 X
}
' D, E8 @) R" P8 p# b当编译和运行该类时,将出现什么:1 v2 k& ~) v! F4 J0 \" p, t% _
A. 程序输出“method 1”
) I: e/ M! W+ UB. 程序输出“method 3”* U x: J1 D4 t) G
C. 程序因为第15行而出现编译错误
$ r! D/ T( S& v. RD. 程序因为第15行而出现运行错误
3 D4 h' \" b. o) H9. 以下哪个接口的定义是合法的:6 J6 C9 K5 L0 j" j! G
A. public interface A {int a();}* q. i* N6 l# Y8 k& y) c. I5 U
B. public interface B implements A {}+ N u6 j! f; H8 L; B" g& N
C. interface C {int a;}
; n1 r: U( C) \. a- x6 wD. private interface D {}
9 j6 \ j7 S! H8 M7 Y10. 读程序:7 _5 E1 F3 K; x+ h: K4 _( C
1. //File SuperClass.java
) P( X. s6 R7 ]' W6 o R) g2 p4 j2. package MyPackage;
( _0 ^# D8 I' q' Q" N# ?3. class SuperClass{
2 F; f7 b6 `* L# p' F2 k# w4. void myMethod(){7 ?& e" B& l) R0 w$ E$ v9 r8 y$ E2 G
5. System.out.println("SuperClass");) T% S8 M' A8 s* ]+ A
6. }) X- `: N( S( Y% m& X5 X
7. }$ z" N: I/ r: ?! r( I
8. //File SubClass.java2 p% t; w) P+ F+ O9 w Q) {
9. public class SubClass extends SuperClass{
; P0 H# l/ q" N& X10. public static void main(String[] args) {
# h; ^( F" b* N: k11. myMethod();6 p9 h- b1 k. d' R" I
12. }, ], x: Z- E( J3 T5 B8 w: ?
13. }5 `9 w, z- W$ s3 k& u( |
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:# o$ S6 s1 O, m5 g& U2 E# a9 o, Q
A. 两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
, f) B5 b4 y5 b$ uB. 两个类都回出现编译时错误
* `" ^, K5 W+ ?, fC. 两个类都可以编译通过,但SubClass会在运行时出现运行时错误
. R: S/ y/ h* C; d0 xD. SuperClass.java可以编译通过,但SunClass会出现一个编译错误
" K5 q9 m( G& s) S& l$ j11. 读程序:
! ~1 R+ ^# u* X1. public class Test{2 {0 I9 Q. P! F& x; x0 E4 Z {( s
2. public static void main(String args[]){" [& k+ d7 {! q& W+ g: J5 m
3. int[] i = new int[5];
$ D& o' W1 G4 q0 z6 n; N w5 y, T4. System.out.println(i[5]);
7 g' f% ^ J- Z, N8 I! h5. }
% w8 x% O- m9 X# e2 M6. }: X0 A) g( D! ]6 I! N" \1 f
当编译和运行该类时,会:
$ v; X& M- I- A1 D) n6 kA. 出现编译时错误+ v. w9 K6 A9 z5 H. a0 p
B. 出现运行时错误
8 G- b" h' ]! R* zC. 输出0# e5 {2 a( U5 R8 I/ }
D. 输出null& t. @1 \" S: H$ E3 ?, ?
12. 以下哪个选项是正确的数组声明或初始化:8 b" |1 F; B( w* f. D. `& b
A. Array sizes = new Array(4);" j1 c( i" ] U% O
B. double [] sizes = {1, 2, 3, 4};
u7 A5 o! j% W7 a1 A% PC. int [4] sizes;
, v: S9 d$ v7 ~/ w1 i$ x& r u! FD. long sizes [] = new [4] long;! W' t: `* Z3 g% k; p+ a
13. 读程序:
+ h- ? }# o0 i" M1. public class Initialize{
5 l+ O/ `# `' o+ G! o* p2. int x = 200;
& a' x+ _4 M6 x& a3. static {
7 Y5 A7 h2 X" T) a! z4. int x = 100;
R- q/ s1 h% i9 v% }, l( b5. }
* J5 E# ~9 k. N3 U6. public static void main(String[] args){
5 E9 }; m8 z/ ~ C& D! g, E7. Initialize init = new Initialize();" k1 t1 F/ p! t/ N
8. System.out.println(init.x);5 c) ?# i1 Q {+ g
9. }, y0 _- _1 C$ L4 @" z
10. }
. [4 _7 O6 U3 U- X" P当编译和运行该类时:
4 I7 U5 M7 y2 KA. 程序因为第3行产生一个编译错误
( ~4 O( h" R% `B. 程序因为第4行产生一个运行时错误
@6 t: ?2 q/ i" v, YC. 程序输出100$ ^1 c. H* z% ^( J5 U2 p/ h0 a
D. 程序输出2008 j* q& U9 z" ?1 N* q% L
14. 读程序:/ i8 L; A' r: o6 s7 B4 y. U
1. public int abcd( char x) {* y: b; R. ]! S9 z* ~0 b
2. if ( x <= 'M' ) {
( x6 ]3 c K% c3. if ( x == 'D')
1 u1 U) i# D3 d$ e4. return 2;; B" d# P. X8 E' ^
5. return 1;
8 t. b7 ?. w6 V6. }4 a4 j' Z# N$ l
7. else if( x == 'S') return 3;+ |( b4 t7 V4 T' ?7 F$ }1 B3 B
8. else if( x == 'U') return 4;
/ ]7 l. w2 d( C4 W. v& e9. return 0;" P* ~. I+ L. m1 U
10. }! y$ {! V j% `5 ?; i
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
) F7 ~# o( ?$ M7 H- AA.‘X’
& t% g: {8 F8 W2 j! f( K8 b, M. LB. ‘A’( Y' m$ y! w o' [/ b* i
C.‘D’, U1 d( A) S" h0 f. Z! e9 e
D.‘Z’
8 z9 |) w& c: |4 c15. 读程序:
9 p2 h& s& h+ \5 n1. class TryTest {
# v4 |- F3 ~6 k) k2. public static void main(String[] args) { C; Z' c; O2 s2 `7 Q
3. try{
) m+ Z C% Z6 E, K; g& B* Q- s' t4. System.exit(0);! N4 O; `2 y( K2 ]5 s0 i9 @1 v# p
5. }. |& t$ N; | C
6. finally {; p+ t$ @3 B/ k( Z$ Y5 n D1 Z: d
7. System.out.println("Finally");
8 m/ I" j2 u$ {$ k, @; i8. }
2 q& L1 `* g5 ?8 V& @6 r4 p9. }
, d P1 e1 W! t- O$ p10. }
0 L+ _) b1 Q7 l当编译和运行该类时,将:
( K, R5 }: Q+ W) j* uA.程序因为第4行出现编译错误
/ ^- r' R8 k# k7 \: V. v4 F" x _B.程序因为第4行出现运行时错误) t( j+ U. D6 |, y
C.程序因为第6行出现编译错误
9 ^* { h: \1 G/ [1 |" D2 GD.程序因为第6行出现运行时错误' ]4 o% w0 M' D8 x
E.程序输出“Finally”
2 z2 I; u4 m# ZF.程序可以运行,但什么也不打印; i! p& A2 m% z3 S2 k. r& L
2 K+ G& _6 z; v& }8 k. ~7 y( F
16. Given the following variable declarations:2 U2 s2 b4 b' l+ t$ F' E) ~
Boolean b1 = new Boolean(true);% x+ B. y% t- C
Boolean b2 = new Boolean(true);# s1 T8 b6 ^$ u2 Z- W
Which expression is a legal Java expression that returns true?
0 W1 |* n: z+ g3 k, r2 d# wA. b1==b2
$ F1 Y, @2 |1 L4 s8 ]B. b1.equals(b2)) f0 }# X' z+ N- K
C. b1&&b2
) o$ ^6 n, M- E. ~6 X4 {9 DD. b1||b23 h+ B, \% g3 U i, M
E. b1&b2& R. D f' e! g& L- t
F. b1|b2+ U [" B) U( j0 N9 b
17. Given:
% U% d/ a5 J3 z, \, \' ^! ~4 |1. public class Employee {
7 J: i1 K2 o& N8 _ N2 O% v1 u/ M2. + U( Q" T& Z0 C% e0 M7 x
3. }( x7 n+ h7 [; b9 J- U3 E) O
4.
% `. T: s: ~( ^0 k5. class Manager extends Employee{5 ?7 y3 b! f3 K# j/ ?& Y- D3 i" u, d
6. }
2 M% N6 X& S6 E M$ b8 nWhat is the relationship between Employee and the Manager?
! k! W5 z! s n2 m, PA. has a
8 H. X2 w m: Z* R5 wB. is a6 X4 i) s% f1 K; D- S9 r8 R
C. both has a and is a
2 d: M6 l% N+ f8 u* p2 cD. neither has a nor is a* E# R1 _& I! {. b. e- I9 J
18. Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
& j1 E7 f0 T* Z$ {9 RA. BorderLayout
) W) m. l7 Y6 ~6 |, X( `B. FlowLayout o. E1 w: ^* G5 W
C. CardLayout
1 D# G, m) P: e6 b9 rD. GridLayout0 v7 M* J2 u' f" Z7 R" X% W$ i
19. Which of the following AWT components can generate an ActionEvent?% F t- Z+ s. Q) m+ ~" b) h
A. java.awt.Button$ Z; i- N4 m! B4 K( {7 F% s% ?
B. java.awt.Panel. k3 Y$ U- J& |' X9 H
C. java.awt.Canvas
) o2 J. S, v f% B3 ^. Z5 O7 v6 M6 \0 JD. java.awt.Scrollbar4 w+ @6 N, Q5 \& _, L
20. What kind of Stream is the System.out object?2 v( X/ {9 }% F$ X* ]* ?4 Z
A. java.io.PrintStream; D: B( B1 b6 q& e% T
B. java.io.TerminalStream7 G1 y( F5 z2 N v2 \5 ~' w
C. java.io.FileWriter6 v" h% D7 [+ K& |9 a- ^
D. java.io.FileWriter
9 B& E' U+ g) s( u4 c# ?6 K# p8 e21. Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)
; F& S0 Y$ W* ZA. java.awt.event.FocusEvent
3 f8 ]8 F S9 r& V# ^8 i& G: O3 FB. java.awt.event.KeyEvent3 ^# |4 x6 q' p' f! ^! y" p( x
C. java.awt.event.ItemEvent8 h0 u1 X! A; s5 C$ u
D. java.awt.event.ActionEvent
* G9 r& K: H0 [4 }, a: l5 I1 t22. Which of the following methods are static methods of the Thread class?(双选)
/ Y4 ?( A2 g' b# J' K! WA. sleep(ling time)
! r$ l* M% g6 k+ v( i \- R0 b% zB. yield()
5 U$ [4 J$ o) J# D" t% `3 eC. wait()
8 o5 g; J' @+ e! R' B1 PD. notify()% j4 Y3 U- b0 y& ]1 m; o
23. Which method do you have to define if you implement the Runnable interface?
1 S2 Y5 n% g4 e9 M: @A. run()2 J4 r; ]5 T4 b0 k
B. runnable()
- i/ M4 H+ B" ] P F2 {, y$ vC. start()
% y+ q% Q. U; r. i ED. init()$ @, C' D# e. R' J! D; M
E. main()
0 I/ T% \8 x8 H7 ~$ I24. Given:1 f: m' q" w% s
1. class MyThread extends Thread {0 d$ E4 Z$ o7 I* r
2.
/ P {( Y3 M" S9 U( V+ W1 c3. public static void main(String [] args) {& k$ V; G/ O/ Y3 Q$ Y5 r
4. MyThread t = new MyThread();. g. N- S4 ]3 D' M1 J0 v, R
5. t.run();. A/ G/ ]% y& Z; [
6. }; h2 W* r5 X* p+ `' r2 d. e n! l
7.
( f- k; J+ n, a8. public void run() {" G( R; h2 u& b$ G; D {
9. for(int i=1 ; i<3 ; ++i) {+ r3 r2 ~' d. B' p& c5 }
10. System.out.print(i + "..");
% w) S: N( o( P. V: k7 W3 Y11. }
. r4 `4 b& M9 G/ [12. }
* h8 n& K8 [# [$ }. k- {- i3 _4 A9 R13. }7 |; B# K, {: I" D
What is the result of this code?C
z" U6 e0 G, e) p# B& sA. This code will not compile due to line 4
% o r5 g7 w+ oB. This code will not compile due to line 5
" p5 _- T) m. @8 n! C6 vC. 1..2..5 s3 f m! N, j8 N" a+ J0 Z! }) G
D. 1..2..3..$ t6 W! F; A @$ z
25. Given a local inner class defined inside a method code block, which of the following statements is correct?
6 H8 a( v; H( C3 b6 UA. Any variables declared locally within the method can be accessed by the inner class
. f4 L7 p' @0 }5 o+ I# rB. Only static variables in the enclosing class can be accessed by the inner class: V' u( Q! V; U8 D ^
C. Only local variables declared final can be accessed by the inner class
8 H, |! z3 b' Y) p8 ID. Only static variables declared locally can be accessed by the inner class.& G) z, u# G- X) B: B
; Y8 G8 q* L8 _+ C H' B, s- R/ [( |. U. @2 K y! ?# x. @
: X9 r+ i: D* v% C8 a0 V9 a6 c, [26.public class SychTest{
9 K0 W* K( G8 y private int x; 5 i4 q2 g: X, \
private int y; 7 k0 B8 E3 x) M5 [ A% Z
public void setX(int i){ x=i;}
9 H/ c% |: O! A. s' J public void setY(int i){y=i;}
4 ], ?9 p5 Q/ H8 \; p* d public Synchronized void setXY(int i){ . G. Y% a. e! N2 b
setX(i); % v) l% l+ e+ z( v2 V. u0 ]
setY(i); ( s& S+ P1 z& }# A$ v( ?
}
* \* b0 c) R8 u; c$ g public Synchronized boolean check(){ q. v+ ]' K3 C. N. L3 D
return x!=y; 8 }) q2 M7 D7 w3 H
} 1 L6 D! ]; s U. Z. l
}
/ s, Q# l# [* G C0 [ Under which conditions will check() return true when called from a different class?
/ ^* y" ?' L' z' W, L A.check() can never return true. 4 ~$ w5 f; x, e
B.check() can return true when setXY is callled by multiple threads. + v9 L3 M! R1 g* }- n6 L- X& S
C.check() can return true when multiple threads call setX and setY separately.
! x& A9 g' |. ^, }' O9 z7 K1 M D.check() can only return true if SychTest is changed allow x and y to be set separately. / u, g) z1 R5 Y; F% D' v8 ^
) Y9 a! G# l6 U: R0 z) H2 Z
27. 1)public class X implements Runnable{ # b! G7 {' h5 G: \' f3 P. l# Z) M
2)private int x;
5 [. O6 a6 q7 h 3)private int y;
: e/ S, t7 z/ t9 s9 t8 X3 O. u/ D 4)public static void main(String[] args){
; T8 R5 ^ `1 ?! i/ C# T, Q! S 5) X that =new X(); ) F6 u0 u. r2 K, c9 f" s) @
6) (new Thread(that)).start();
! V' j' }( @- i# J 7) (new Thread(that)).start(); 1 Q+ }, @+ B- Q& i
}
- q% k- N5 {; m 9) public synchronized void run(){
" H3 O- w E0 Y 10) for(;;){ 6 p: n8 b: M9 J6 F
11) x++; " N. _$ L8 z' }5 _) @3 R; C! ^) k
12) Y++; . K/ b" e5 i3 j3 E1 q
13) System.out.println("x="+x+",y="+y); : a; w; H- f3 N. d
14) } 0 T9 B2 O. [. i- x6 J) A; b" C
15) } 4 J! s7 ^8 ~9 B% M" p* Q
16) }
% T0 ?6 Q. T- |3 g$ J4 Z what is the result? 7 O Q1 z( s" C( C- P2 s/ O+ N
A.compile error at line 6 4 R) p$ l, `" Q) z
B.the program prints pairs of values for x and y that are % o' f0 y1 B6 h
always the same on the same time R! L, b. i$ i: C* A- d6 ^2 s
; c: D! L( d3 q" j. ~28.class A implements Runnable{
) O v8 {% i3 j, e( u' d int i;
" |4 U8 m3 c: B public void run(){
9 H/ ^+ ]$ l) E) n: q2 R" F try{ , {4 a p" P8 E0 c5 e4 O G. _
Thread.sleep(5000);
1 `; r% b1 l! r0 A! Y i=10;
0 Y+ w5 L) T4 H4 G }catch(InterruptException e){}
6 M9 P) {3 f: ]7 p* I+ T8 f } 6 x6 q. x$ g1 F+ }2 a
}
9 y5 X, w9 Q" W% L public static void main(String[] args){ 4 C5 _; I! ?& W! @+ M7 X7 n
try{
( M" t9 ~4 T5 y' H. q Z6 V3 p A a=new A(); * x0 X1 _2 @' c& E- e
Thread t=new Thread(a); % s9 s- P# l; ~8 n7 p
t.start(); 3 k5 M" N9 I& v; t/ [( H
17)
1 \" q' ~) D/ c% f6 O int j=a.i; ( Z6 @/ T# D4 e @3 o- |% v
19) " |' j/ R' B, h7 t
}catch(Exception e){} + D$ V& v [- C: u$ A8 ?/ M* C
}
6 i* _5 r) V: |2 D! v8 g* r5 y$ d } - ]* w8 C% E' ~6 q, ?* n, Q0 N$ {. t6 o
what be added at line line 17, ensure j=10 at line 19? & {) i7 P2 T6 Q" d
A. a.wait(); B. t.wait(); C. t.join(); D.t.yield(); 6 M5 u8 A) `4 i# i0 e% x
E.t.notify(); F. a.notify(); G.t.interrupt(); 0 R2 k) M4 M4 a" L+ [2 ]1 D
29.1)public class X{
; v; ^2 G0 A1 m: M 2) public static void main(String[] args){
' F7 L/ `7 [" K2 ? 3) String foo="ABCDE"; ( [9 c7 L: s0 {) a' \/ c1 p
4) foo.substring(3);
0 w( k5 `2 E4 D5 h 5) foo.concat("XYZ");
5 G: \/ @4 @! \3 Y: ?' j 6) }
( c }/ E: |( S 7) }
1 Y+ e: \5 X: Z$ l. |, A what is the value of foo at line 6?
* T( L" ^: u, d) Q. }9 w% p30. public class Test{
9 Y/ Q9 N$ }1 P, d public static void main(String[] args){ - f+ p. J1 q1 s* F; Z
StringBuffer a=new StringBuffer("A"); 7 ~0 X9 b; v: l1 m2 z/ R! ]
StringBuffer b=new StringBuffer("B");
, l! {( d) U0 V5 x operate(a,b); 5 X* [3 d; v7 u; k2 A3 g
System.out.pintln(a+","+b);
q3 h9 x& L( } }
" k- X8 J. U8 l$ x public static void operate(StringBuffer x, StringBuffer y){ 7 {5 `9 L9 B6 `+ p, `% _
x.append(y);
' _1 s7 |. O6 x) f2 u1 ?5 Q( g y=x;
4 P- `: Q; R. Q. e0 C6 [ }
" |5 X8 r& I: X3 D2 Y } % ~8 [0 [' U* g8 q
what is the output? |