Sample TextJava培训考题0 U2 h% M4 d9 f9 h; Z
1. 给出以下程序:
' g/ \4 N1 ?: E$ r$ B1. public class Colors {
. w0 x% @" @4 \5 W2. public static void main(String args[]) {
7 x5 X# m. R9 }3. int n = 1;0 e5 j0 B( O5 U
4. System.out.println("The Color is " + args[n]);* J3 C0 ?7 L& V( I: C/ U& ?
5. }
/ x! M: b5 S3 l6. }
( a5 V) l' Q# B7 v假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”& ]# S5 U1 x! |, M2 c7 `0 r
A. Colors red green blue yellow, T1 [1 x1 M# m2 c2 Q' v8 _
B. java Colors blue green red yellow& O/ Q5 A& E5 _
C. java Colors green blue red yellow% e ^0 N* W _6 P! W+ L. v5 B
D. java Colors.class blue green red yellow7 }$ \6 A5 e9 _7 M. ^) }1 w
E. java Colors.class green blue red yellow
* A( k; N4 F1 f9 s0 n5 s2. 读程序:9 U/ F- c3 i( n
1. public class Test{4 d- l m! s- E3 c8 n( C" X! H' k
2. public static void main(String args[]){( s4 B9 r( Y% I D+ A% Q$ ^
3. char c = '\u0009';
2 ~: `6 p$ C9 R9 q4. if( c == 0x0009L)
. ]6 N6 }) x1 U( @4 \5. System.out.println("Equal");
+ w2 \1 O* Y3 b6 G6. else System.out.println("Not Equal");9 {7 q) M; D& c3 W6 x
7. }5 ^" M; f. V2 E$ C) c- ~( M5 S
8. }' W, H, z# m% H* w2 Q
当编译和运行该类时,将会发生什么:
& u- l6 H& Y& m, gA. 程序因为第4行将出现一个编译错误 L4 D: c% u3 L2 u/ f
B. 程序因为第4行将出现一个运行错误& _1 t' M8 P p# S% d
C. 程序因为第3行将出现一个编译错. g: Z" O5 O9 W2 E- }
D. 程序输出”Equal"+ I1 K: I# Y3 k5 n1 R* Q0 g8 n
E. 程序输出"Not Equal”
; |4 Q) Z8 u9 B5 K3. 读程序:6 @ _7 q2 D) t
1. public class StrEq{! N3 E6 l, ~, P
2. private StrEq(){; h0 a/ m W4 G
3. String s = "Bob";
! x: ? f. t) G& i" Q. E. I4. String s2 = new String("Bob");
7 x5 S2 y" v% Q1 _- _5. if(s == s2){" C& X: e# M4 q h
6. System.out.println("Equal");/ p% @; `9 c0 `2 |6 M% T
7. }
2 H6 u- O; F2 u8. else{
8 f. A5 h3 Q' B" m6 p9. System.out.println("Not equal");4 \6 E" ]* n( z
10. }. y1 K! L) P; K! z& l- u$ B
11. }
6 g' x* f; c! p+ z$ Q12. public static void main(String args[]){
8 A% U0 e$ r. E' P% y' _+ ]3 `, m4 ]13. StrEq s = new StrEq();9 u6 X& ?9 U; T0 ^5 ~# S/ X
14. }3 r. _: i3 P! e3 s* c+ R
15. }
# a: s I% u# Y: u# f# G/ V当编译和运行该类时,将会发生什么:( p" p o+ P9 M9 ~
A. 程序能够编译,并且输出“Equal”
V2 T) |: N- B8 F. Q' \B. 程序能够编译,并且输出“Not equal”
2 {% @' j* F: K4 BC. 程序因为第2行导致一个运行时错误
5 g3 p" n; w7 ^( U7 g4 r' jD. 程序因为第2行导致一个编译错误; |% E0 G8 L( _) n
4. 以下那个赋值是非法的:9 P) ]3 e0 X4 W# v2 v* t4 u
A. long test = 012;
# M7 ?2 t' d6 ~( f( V' vB. float b = -412;
3 |* e7 U4 Z) x8 E0 ^C. int other = (int )true;- I0 q% U" R7 C' c; E. Q2 ?
D. double d = 0x12345678;
$ n" d6 K0 \4 _5 r7 B3 }E. short s = 10;
0 ]9 d4 B; U6 Z8 y) [! b& Z( b5. 读程序:+ k( M) Q* t% B9 g* g; I, ^
1. class CompareString{7 O# l3 b; T' u, o3 ]" b& W7 o0 n
2. public static void main(String[] args) {
0 ]9 p2 k& O- P, W6 Y2 B6 n3 z3. Integer x = new Integer(5);/ h# K3 ]6 L, A
4. Integer y = new Integer(5);! U: h- k2 W* c# ?& W" M% c
5. Integer z = x;% ?4 z; [( X7 C$ S. E3 X
6. if ( ______ )
) A. a `* T* P6 ]8 m1 H7. System.out.println("true");# y1 a5 v3 n- i3 e6 _, O5 O. {
8. }
! l& ?* E) O: B* \% M' v' l% w0 R9. }7 }9 }. |# N1 s P
以下哪个选项填入第6行后,不能输出true:# B( F1 n& t8 k% N3 [
A. x==z
. \8 O6 j& o: o# ?: H8 a; OB. x==y G9 H/ J6 c8 E
C. y.equals(z)
4 y+ K/ }* C+ a4 W4 g- h* DD. x.equals(y)9 G2 c' Z/ q* j
6. 读程序(双选):% [* B/ j# m. @
1. public class Declare {
G, G- s9 n" y8 E7 S2 s D: a9 C: U! C2.
1 y( ^2 f, F% {4 w3. public static void main(String [] args) {
' ^2 ^9 d" ?& Y+ F! k. `0 R3 b4.7 A' z! I" o0 ~' O7 H
5. System.out.println("The variable is " + x);
6 q, h- O" z6 Z1 S& p6. }; c6 f' v1 \) U' g V
7. }
+ k8 T6 B6 y9 o6 @* Z9 m% L7 k以下哪个选项中的代码可以使程序编译通过
) M) N' p" h0 `$ nA. 把“int x;”放在程序的第2行, @/ U) i1 Y. w) _6 H z
B. 把“int x;”放在程序的第4行
; P; V& x2 c4 W& E: \3 n7 sC. 把“int x=5;”放在程序的第2行# I/ Q6 [4 H# h" k2 V5 h7 J
D. 把“int x=5;”放在程序的第4行2 l7 e% |$ ^: p$ o% F1 p
E. 把“static int x;”放在程序的第2行' t% |1 q/ e5 G
2 M( v k! \& b* l( ?' V( j( s1 A. K0 U" ?$ Y# ]6 Z. N
8 U* Z' }' u* r1 s! y7. 读程序(双选):5 K& F( ?& f' C: f
1. public class Child extends Parent{% v! P" ^/ E- ^
2. int a, b, c;0 F; x( k% h" L! V3 o) Q1 T" i
3. public Child(int x, int y) {$ w; {* I4 d; T* j; ^# m' b j
4. a = x; b = y;; P4 A, B3 g0 p* E& l
5. }4 s; z! ^( k! o+ \8 g5 r
6. public Child(int x) {
: B7 ]7 J" }" l- f) X% l# d M- x7. super(x);% T+ b: K f6 `5 z9 y
8. }
$ S9 l. w; y; l2 h; x+ l- ? G" B9. }3 n e6 C _/ @% M. ]0 b+ Z% \
为了能使该类编译通过,下面那个构建器必须出现在父类中:
! c* f; r* g8 f+ P6 s% z- u8 ~A. public Parent(int m,int n)
3 ]6 H/ l& O9 n0 pB.public Parent(int m)% Y4 Y& Y, p0 k5 t& x% m# O; i7 H$ a! V
C.public Parent()! r' f( m2 _! n6 T! \8 b& w! |6 F
D. public Parent(int m,int n, int o)( T$ t; d8 N( _
8. 读程序:, ^- S$ W6 K' o0 m5 a
1. public class Derive extends Base{
& b$ t, n4 a6 d2. public static void main(String argv[]){
# P0 u9 `* c/ F6 n2 Y6 V1 P3. Derive a = new Derive();
: u- o, r ?3 x( Z" i' z8 v4. a.method2(); X9 ]9 H; \: z& C" q' U* v
5. }
( K$ n8 K8 ^5 ]) G6. public void method1(){
' S; s* Z: \: ]* Y4 T8 T: h7. System.out.println("method 1");, m% v+ B; b5 u
8. }
! ]8 W1 v8 W, t( G, z r9. public void method2(){
" \' `! V4 G' `/ r: s( G10. method1();
8 I' ?! J: v; G# k+ |! t3 c! G; f11. }* m" c) V; i6 i+ W ~. B: j/ ] q6 ^
12. }
: p9 s0 l# l" S# P4 A13. abstract class Base{
2 W- X0 O" Y) Y( P14. abstract public void method1();" L, \. ^* C5 N7 J
15. public void method3(){1 @% C( A# _6 ]( B; H/ X0 `
16. System.out.println("method 3");
$ [4 k9 j/ W9 J- b$ \. U0 W17. }& e5 e2 I2 x, p. s" G
}# d% _( G3 X! a! v* _
当编译和运行该类时,将出现什么:1 A3 O1 x% a! I
A. 程序输出“method 1”
0 J l" d( o& H, N$ _; }, m3 mB. 程序输出“method 3”
6 ~3 s3 M) h) m" z/ g: U" kC. 程序因为第15行而出现编译错误; E. _! c& y8 t0 h: r
D. 程序因为第15行而出现运行错误$ c! C8 E. f% ~9 b4 n6 i* n6 ?
9. 以下哪个接口的定义是合法的:
, V. H5 l( K+ C" ?. O, e' \A. public interface A {int a();}$ w# F k' ]+ _5 b
B. public interface B implements A {}$ ^1 O! @9 {2 j' i5 Q3 a
C. interface C {int a;}
- W! m5 M6 a2 CD. private interface D {}
+ G/ y# ]0 g4 j10. 读程序:- N4 s8 u1 r) q4 I) _8 C7 ]
1. //File SuperClass.java
% i8 g2 \# P* ]$ O2. package MyPackage;
5 A& @$ Q5 z+ Q' N; @3 A, T3. class SuperClass{5 u; K& B! N0 V
4. void myMethod(){$ y6 F5 c- E* X2 E
5. System.out.println("SuperClass");2 w5 k4 L% E3 j
6. }
7 k6 V% i' x5 Y }$ H. Q$ n7. }2 N- z& ~ t% y0 ^, b1 H2 b9 U
8. //File SubClass.java
4 I4 ?) @! m5 i' e6 i# E9 m9. public class SubClass extends SuperClass{
1 R- ?4 b' n" [2 c$ N7 V6 W10. public static void main(String[] args) {; e! s- `; a* ^- G5 p3 ~. p3 E: y' O
11. myMethod();
; B1 `0 X4 y2 b) [9 ?12. }
7 a. ?2 U( d) W. T0 W4 m13. }& k: _: ~3 K5 {* [3 h
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
5 a$ y. e6 ]. V- g# c" K3 s9 ^- ZA. 两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
& U |0 S/ Z9 ?9 t0 G+ ~B. 两个类都回出现编译时错误
& X/ `# ]* @4 ?" }3 g {C. 两个类都可以编译通过,但SubClass会在运行时出现运行时错误
3 a9 {, K4 \/ `6 OD. SuperClass.java可以编译通过,但SunClass会出现一个编译错误
' F( E- ]- v' ^( b11. 读程序:& o) l2 V1 [! z
1. public class Test{( ~( a; I# F/ ` j1 H8 g
2. public static void main(String args[]){. o- K; x% Q8 }: l {
3. int[] i = new int[5];5 \2 u9 y! @/ j' i- \+ t; ^8 C
4. System.out.println(i[5]);2 O5 R/ N0 g* p
5. }
/ s X3 o- S7 H5 K2 A6. }
2 @% ]3 T1 p y; E; r当编译和运行该类时,会:
2 W2 B# O5 o' a% o9 KA. 出现编译时错误
9 V' `6 X9 z" x# h; y5 {7 u! \: D( `B. 出现运行时错误: b: w3 M1 t: m8 C7 R
C. 输出0/ Q2 H- |$ z9 O) X; M7 d$ O
D. 输出null% \# P7 C& T& Y) `' s5 p
12. 以下哪个选项是正确的数组声明或初始化:. m# C1 |1 G( ~) G: W5 s
A. Array sizes = new Array(4);
% {5 E6 c/ @3 xB. double [] sizes = {1, 2, 3, 4};
. Z6 q( B- `2 f; T% ]+ JC. int [4] sizes;7 d h2 x) d& e1 n: e: w
D. long sizes [] = new [4] long;
4 C) _4 y; i8 C) A# e. G; ?13. 读程序:
6 O& ]. b' R0 m) N+ k! @: `9 ^3 b1. public class Initialize{
7 k+ d( J1 w; |2. int x = 200;/ Z1 d# ] a, m1 m9 y4 y' {, _/ I
3. static {
9 X; ?" |$ j* ~8 }: R4. int x = 100;! t7 s' b3 b; a
5. }
( N0 i# J0 L* G6. public static void main(String[] args){1 Y! Z2 Y# _7 y5 U0 o! w
7. Initialize init = new Initialize();
. u* n/ z# `+ W+ ]) ~( u; l" i8. System.out.println(init.x);
$ s4 ^9 Q$ o4 F9. }
7 r( T: |8 Y0 o4 d. d10. }
! j7 D6 m. [$ L& A3 q当编译和运行该类时:5 Y3 V9 [ Y8 T- Z
A. 程序因为第3行产生一个编译错误& c. [+ y2 c E4 h7 H* H$ P* `, \' _
B. 程序因为第4行产生一个运行时错误. ?1 X; o, g4 f* e/ h6 d6 L0 J7 W# V/ P
C. 程序输出1003 P# ?& E0 q3 d* }- k
D. 程序输出200
, r6 _4 U7 Y/ R8 b3 h* V14. 读程序:
- d; I4 m* [- @$ P, F0 i1. public int abcd( char x) {7 K: V. b* N& ^
2. if ( x <= 'M' ) {
. e$ E# h: \3 c1 P. _7 a3. if ( x == 'D') % ^0 i9 M7 w( N0 ~% N$ e+ l
4. return 2;
. G; T1 ? _8 Z* f8 n5. return 1;
4 ^) g' z( Q* k# |4 s/ H- Z6. }: Q. ]# k4 U% L3 a
7. else if( x == 'S') return 3;" _1 ?: b- M. F1 t! x
8. else if( x == 'U') return 4;
* c9 Z4 j4 n7 m7 ~9. return 0;7 g! p/ K: x1 Z" Q. [9 v2 `
10. }, i/ B2 O# E8 ^9 y, y/ i% E
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
3 }1 d: u p8 c$ JA.‘X’
5 x1 m' R! |7 s2 ?( NB. ‘A’
, }3 Q& H0 k. u( ]' U2 @5 RC.‘D’
+ F" z C) C4 n% nD.‘Z’
1 A/ Z. o$ w0 _* G A15. 读程序:
) F2 G3 y2 h1 N! S! r1. class TryTest {
. J* d' Z3 J: E# ?9 O' j/ k4 {2. public static void main(String[] args) {
1 I) v; x1 x5 P2 \3. try{& Z+ @3 M! b, ]+ F
4. System.exit(0);# U0 W T {# c$ z; S" V& G
5. }+ b6 ^& S4 o6 c
6. finally {3 Z/ B0 P! @. s, |: l. {
7. System.out.println("Finally");5 p, M# I+ q' M; [% m
8. }
* o3 [$ T8 {. ^% e* b7 s+ G8 U9. }
) @& ~: x5 c/ @' K3 v% l# P10. }
, `' s N# X( n0 i, `0 T当编译和运行该类时,将:1 R6 \; k7 U, ~
A.程序因为第4行出现编译错误
1 _4 Y/ m6 ^9 o. o5 nB.程序因为第4行出现运行时错误
6 x- G" Q; G6 b* O3 ~C.程序因为第6行出现编译错误4 }0 E7 l% H7 ~+ p7 W* m8 k9 U
D.程序因为第6行出现运行时错误
1 x N+ J2 x( n1 |E.程序输出“Finally”; ]1 P* y" s { O* g U+ c" h
F.程序可以运行,但什么也不打印$ T- t- G$ z5 }' a
$ P( [. W& g0 p0 o+ [* c# ?7 [16. Given the following variable declarations:: A! b" ~* c* |, \9 t8 y$ C
Boolean b1 = new Boolean(true);
" b$ Q4 f, H8 d3 }: |Boolean b2 = new Boolean(true);
+ a& Q* G+ H% Y2 zWhich expression is a legal Java expression that returns true? 1 X# V6 }& v, i% ^$ O2 D5 [! y9 K
A. b1==b2
% G6 d, r: f1 ^1 {B. b1.equals(b2)4 o% }; k0 ~+ j* V4 v* s+ t2 I
C. b1&&b2
/ m% }* m( y# y) l& MD. b1||b21 b, K/ _" c! o8 q. z
E. b1&b2
8 s0 L6 t2 q( x/ R5 eF. b1|b2
$ R" F' I4 g+ |2 y' W) \/ o17. Given:
4 Q0 |8 m+ S3 {, R: w1. public class Employee {. l' g( O/ @- q* Q2 y( X
2. * \$ G# U' c8 U# z/ \- \7 B6 N
3. }
4 O `- b& E; ]; F$ F9 x+ z4. + `4 w/ X. @ W9 S' ^! i
5. class Manager extends Employee{
" e. J: j4 _( T6 U9 @2 A9 A% R6. }
0 n- w' K1 \& s8 V: Y- R+ w9 [What is the relationship between Employee and the Manager?
3 B& z) |6 ]+ B! U5 EA. has a+ w1 \/ r. H: e \* T! v/ X, q) J
B. is a( `/ G' r6 I% t6 |/ ]/ H
C. both has a and is a
. L; Q: }2 y1 P7 I5 jD. neither has a nor is a
3 P* [3 j) I6 \18. Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?+ |8 n! ?. f, K3 R3 l. f
A. BorderLayout2 Z& y6 T7 `% _% S4 e
B. FlowLayout
) d6 N# c: Q- u* H: c! } @) e; }C. CardLayout3 d9 B3 V6 E+ g& Y C& C g( ~: W
D. GridLayout/ A! }" y. ~7 {- R* a3 y5 y8 N( [
19. Which of the following AWT components can generate an ActionEvent?
& h7 f; o8 v( n1 e8 B' Y/ W; M$ m5 oA. java.awt.Button
( \8 T( S1 F t8 v0 t$ m/ W* |* PB. java.awt.Panel
- W1 @9 R$ k$ [( Z: @4 f8 o8 Y* Y4 lC. java.awt.Canvas
9 d% @$ o9 [ F( f; ~- H2 jD. java.awt.Scrollbar3 h* r5 T( h0 l) j
20. What kind of Stream is the System.out object?+ h% g( _. u4 U+ E% m
A. java.io.PrintStream
2 g% l. [1 v1 P% [B. java.io.TerminalStream' W2 z2 N* \9 l2 T8 Y. P4 ]
C. java.io.FileWriter8 P) Q$ `0 G7 a9 I
D. java.io.FileWriter
/ @, a. r) V+ v$ C5 ?7 A1 F21. Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)5 M) Y+ u0 T2 v
A. java.awt.event.FocusEvent
: o4 v' ^( x! s/ Y5 ]B. java.awt.event.KeyEvent0 T, W. Y, ]$ s* h+ c, U, C. J
C. java.awt.event.ItemEvent) ]/ o. D2 s: ~6 _, S
D. java.awt.event.ActionEvent {) J3 {4 m+ s3 [4 i7 F+ ]; ]
22. Which of the following methods are static methods of the Thread class?(双选)0 k6 e- x! }' r; R( `' V/ J
A. sleep(ling time)
6 c; E7 d6 `: R! v% hB. yield()
* i4 M7 E9 a5 u4 bC. wait()1 L( ^* V2 h/ d% E
D. notify()9 H8 o5 U+ f7 u% B _
23. Which method do you have to define if you implement the Runnable interface?
9 ~3 Y% {& m! m' u# A6 aA. run()
2 j1 q$ R' w( h( TB. runnable()
! z6 o, P7 `: o4 x1 z4 B/ P1 \# }C. start()
; B/ p' Y. h1 _D. init()- _, o1 r) g V
E. main()' c% Z- z4 X$ w# l. _4 p o0 i0 K1 X
24. Given:
# ]4 }. ], N5 q9 C+ u9 J4 }- z$ y4 R1. class MyThread extends Thread {: L$ X* |# h( v) E! J
2. 3 T/ I% _2 A$ R
3. public static void main(String [] args) {
: b4 X F& T- F. T" }# p) Z0 M4. MyThread t = new MyThread();) r! Q6 y8 Y" B2 y" H
5. t.run(); }8 a& i. n' e. j! e4 K
6. }
/ P a( }% x7 j9 U( C. |6 X7.
7 j4 O! z5 C. ~6 \% e8. public void run() {
+ b# n8 E, R! I9 U+ t1 H6 x9. for(int i=1 ; i<3 ; ++i) {
( K. j8 g; l# H: e10. System.out.print(i + "..");3 q& _9 x1 o$ U3 I1 b% p+ j
11. }
S( |& V* t) B* R12. }
& ]# h# I: z7 C! i13. }) n5 K3 b0 r5 B; W: h( g
What is the result of this code?C8 J. u- J1 N p8 Z f' ]
A. This code will not compile due to line 44 y" {& l% |' k1 g# A7 I' c
B. This code will not compile due to line 5
! F P- s, S; t/ N4 L! G- s0 N& GC. 1..2.." [. u, r) P5 O3 w1 g; I* I! R% S+ x
D. 1..2..3..( m' \6 P- G. J; `% X. A3 }
25. Given a local inner class defined inside a method code block, which of the following statements is correct?+ O2 T8 b& Y* \7 w! O. @
A. Any variables declared locally within the method can be accessed by the inner class8 x9 a( g( m* _1 f
B. Only static variables in the enclosing class can be accessed by the inner class
2 |. z+ @; G" g0 yC. Only local variables declared final can be accessed by the inner class
- y. s7 C/ w, P- Q/ J( _D. Only static variables declared locally can be accessed by the inner class.' k$ B3 R' v# j+ c+ F( n
9 j4 E1 ^3 j3 Q6 u% Q4 y
3 `& n! b# L0 M7 H
1 Z; {6 \. Z0 @' h" a26.public class SychTest{
) i% r- }3 ?' F# @4 ?# @$ e' G private int x;
3 V: l$ {8 K( j0 j3 ]! ^9 }' ~ private int y; ' s; S) _5 \* f8 T
public void setX(int i){ x=i;} P/ k: ^+ d Q+ O* H8 G
public void setY(int i){y=i;} 9 w B: i* U, {0 w
public Synchronized void setXY(int i){ : B# z7 k0 c) w" m' u. I
setX(i);
/ y q! @; B1 i& y setY(i); Q; q2 \! B! p2 M
}
8 e, [/ u7 H7 \7 q public Synchronized boolean check(){
' S' h* I% F1 b. Y+ o4 n) E return x!=y;
/ g2 y' n. l5 M. _; F- G* F } 7 B# `, w! M' C7 r# l6 l U
}
4 G- i% ]% @% v Under which conditions will check() return true when called from a different class?
+ g5 ?# Y0 n: {3 o+ | A.check() can never return true.
8 P3 c: Z0 P0 Y! ]/ I# S+ U! Y- r B.check() can return true when setXY is callled by multiple threads. . f) D+ n7 I3 S6 \. Z f- v
C.check() can return true when multiple threads call setX and setY separately.
; P2 l/ l% Y. R' _ D.check() can only return true if SychTest is changed allow x and y to be set separately. % s4 M3 G- V0 h" S3 Q# Q
, m- W/ J! L3 b- B; T6 w! L2 Q27. 1)public class X implements Runnable{ , Z/ B( P4 T# c, Z* e
2)private int x;
0 |0 ?( x4 i: P1 Z" v 3)private int y;
) V' _+ _7 T! H4 d 4)public static void main(String[] args){
. r3 q7 ?$ W% C. U0 Q; q 5) X that =new X(); . f6 O' g6 @# o4 b6 \
6) (new Thread(that)).start();
0 y+ \0 Y+ R5 J 7) (new Thread(that)).start(); : U7 m+ |4 [% z4 A: q& J0 C
} % h7 C+ o. F- ~7 Z* D6 a
9) public synchronized void run(){
$ X9 W+ L2 u c 10) for(;;){
; p% q6 G6 F- m, Z9 X1 m0 C 11) x++;
! ? ?5 {1 ?0 u: ^) {4 @ 12) Y++; + l0 F3 d. _+ B4 j, t
13) System.out.println("x="+x+",y="+y);
9 A9 ]$ Y" o7 p/ \2 k8 D, V 14) }
: n' s n- _, P& {# P( ^$ l 15) } , b3 I! R4 \9 ]# I& z O
16) } ' Y5 l% l [ y Y
what is the result?
8 h }: {) \6 E4 j( g! t5 d A.compile error at line 6 6 c4 w! o8 f5 [
B.the program prints pairs of values for x and y that are
, [- |8 x4 Y! e0 L* v always the same on the same time
3 g7 n* s* j- O6 D
2 K+ x# o' v. z: q) \! O28.class A implements Runnable{ ' J8 v, @# b4 _" {
int i; 5 T, G0 E% l* z' g
public void run(){
. Q3 S& I& [; m; M% y" K4 I* J try{
8 n- N5 A$ G j6 q a5 R2 [4 j- ]5 ^ Thread.sleep(5000);
8 W( T( {, H0 F/ E* Z8 R i=10;
" j. k( K2 j% k, h9 p9 o }catch(InterruptException e){} ! ]2 c; g$ d; K: ~$ P3 N* t
} & s" A, r3 B" o# I0 O- P
} , {- w, P; r+ ^5 \6 }& L4 l
public static void main(String[] args){ , |2 f* J7 H) @1 m) I
try{ # {% D' h* g) Z! m% W6 O
A a=new A();
- m! c+ s0 f5 F& @: X Thread t=new Thread(a);
8 f8 r; o" \- }0 p! Z t.start();
1 O& I* C; N) B8 P7 B. _ 17)
8 ~+ k( b' n3 A3 ` int j=a.i; * S) ]- Y% |3 o3 j
19) + E% z* j& c$ N( Z( l _, U- A/ v
}catch(Exception e){}
0 S0 O ?/ k" h5 ]$ \ s/ | }
9 w f, k& ?! u7 R. u/ | }
. W3 w9 C/ Z& q: y' j1 ` what be added at line line 17, ensure j=10 at line 19? 9 _5 X4 v, r! i$ y
A. a.wait(); B. t.wait(); C. t.join(); D.t.yield();
* Y3 [# u( F. C& M k) I) H2 c E.t.notify(); F. a.notify(); G.t.interrupt();
& W% w0 g! r0 C5 C8 d" E3 C1 @8 U/ S29.1)public class X{ $ P" s9 D6 B! k
2) public static void main(String[] args){
8 Q- r0 Z2 S# F9 D: I$ e 3) String foo="ABCDE";
/ k8 `/ h V% D; Q9 N: c7 D 4) foo.substring(3);
3 @/ C' G* U% C7 _' W 5) foo.concat("XYZ"); ' p' _/ Y, {* M7 g+ E: p* X
6) } 2 C8 ~# m9 H7 X: e; F
7) }
* G: j6 c. N8 Y3 E what is the value of foo at line 6?
" F1 e0 ]& N3 g! D7 j30. public class Test{ 2 ~! V& p9 a+ @6 v) I
public static void main(String[] args){ 2 j" I) W1 u* D) i7 ?# g; |) |% L8 ^
StringBuffer a=new StringBuffer("A");
* S. l) e% P! V0 S2 X StringBuffer b=new StringBuffer("B");
3 s! Y& Z1 W0 u/ Y operate(a,b);
7 l2 R$ a% d8 m, M5 ~ System.out.pintln(a+","+b); , y3 [- d7 F! r* w+ [% \9 M6 C
} 6 g& S" K. h9 G3 Y
public static void operate(StringBuffer x, StringBuffer y){
" F7 ^$ @( H* o6 b+ U0 ~7 G# @+ l x.append(y); 6 ^2 R/ ]+ l7 j
y=x;
b9 A% o7 Q0 V% s, u7 n }
: ?" i8 K% _5 O4 Y }
/ \0 C9 ~6 q/ X, k% c what is the output? |