Sample TextJava培训考题
) F) u9 W/ l3 l# |! ~) B/ [4 M1. 给出以下程序:
$ D3 [, ^* F; {3 n6 x5 _ o8 x3 I. f0 b5 s1. public class Colors { H- e( L; ?/ v2 L% `
2. public static void main(String args[]) { S% s, K, V& J! ]1 n4 w+ t
3. int n = 1;
" L2 _1 \, ?/ O( l) @! A) _9 m2 [4. System.out.println("The Color is " + args[n]);
4 d- S$ b' N* I" A8 c( {% Q z- X+ V5. }, d% {, K9 T. F7 r
6. }
' _/ X0 B) H% H8 M! C' s# L假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
$ l) r% d& U( A7 M# _A. Colors red green blue yellow" m$ I& ?* p5 A. x( f! B
B. java Colors blue green red yellow! m7 b T8 i' w8 b
C. java Colors green blue red yellow
8 n5 c$ r Z8 [# p+ L3 }D. java Colors.class blue green red yellow
. l) z8 y! V( ~4 a; B0 `0 A; HE. java Colors.class green blue red yellow
( o) X8 y3 g3 W2. 读程序:9 z9 Q0 v0 Y8 z8 M, N
1. public class Test{; I7 ^/ P5 c, }+ t2 d
2. public static void main(String args[]){
) t, n& I O4 w' E) ]& p3. char c = '\u0009';- t6 a, p* G! Q$ d, H9 g% {
4. if( c == 0x0009L)
7 K* |6 B0 ~. d) d5. System.out.println("Equal");' _, f6 z+ |7 S! w5 T5 g; U, x: O( n
6. else System.out.println("Not Equal");) Y9 J$ r: w& E$ b% o0 v
7. }, ~ Q" w- s# J- N
8. }
$ R) ^/ o1 H% Z当编译和运行该类时,将会发生什么:' e! T+ Q& _+ Z) B. T
A. 程序因为第4行将出现一个编译错误
# s4 g5 [; P* y. |" AB. 程序因为第4行将出现一个运行错误& D' r' T# }4 G/ Z1 E7 Q& p2 L+ o5 H
C. 程序因为第3行将出现一个编译错
" T2 c& R: z. tD. 程序输出”Equal"* T- W) v" N6 h9 v& p
E. 程序输出"Not Equal”
* Y. I8 x- }* V( Y( U( }) K2 @3. 读程序:
, b) _/ C j6 P# Q/ c1. public class StrEq{6 a3 P L' Q( |3 O- |) _8 U
2. private StrEq(){
) `" x! o* \# e$ d3. String s = "Bob";4 d9 z6 A, S% ]
4. String s2 = new String("Bob");
( B1 u& C/ H$ ^5. if(s == s2){
4 R) a) J# M" ]. B& O6. System.out.println("Equal");
6 ?2 f* v# D9 k! A( ?$ T' W% y7. }
2 ]) H% j5 Z) k I( @8. else{
$ g" j6 S' x6 ]3 k9. System.out.println("Not equal");
+ |' Q1 u2 U+ A/ {10. }3 I- `4 w* |" E" i7 E6 D& k
11. }
( X* Z; X5 L1 p+ r12. public static void main(String args[]){$ ~1 M3 c) E2 e. l
13. StrEq s = new StrEq();
0 L- V! Z! i$ d: Z8 g6 b$ Z5 H14. }4 |& b, b$ o, A# N/ s
15. }! }; a0 F4 {/ e" u' {" F! _* G
当编译和运行该类时,将会发生什么:
& O9 O) O1 b2 v1 s* w) Z& J" ?A. 程序能够编译,并且输出“Equal”' t0 R9 P3 n' X( Z, T
B. 程序能够编译,并且输出“Not equal”7 T7 J0 ^! I5 a( m$ t J; Z
C. 程序因为第2行导致一个运行时错误
6 ?3 c# \- g- L, {+ jD. 程序因为第2行导致一个编译错误
/ N* g g' O T! D* A! B- T4 i4. 以下那个赋值是非法的:
: F& x, `. |6 N6 T3 CA. long test = 012;
( [# s8 G8 B. G4 ?6 KB. float b = -412;. X; a; f9 M$ O" s% y
C. int other = (int )true;
1 _+ ~# J" L3 n1 y5 FD. double d = 0x12345678;: z, L6 B4 ~+ i6 S8 |
E. short s = 10;
7 @0 ^# L3 P- ^! E% A, O5 Q5. 读程序:) h3 a. r$ W8 ?" H+ ^# g7 |
1. class CompareString{
2 |" r+ m- M$ y6 j$ L9 D2. public static void main(String[] args) {
# Y# F# ?4 ^$ _9 O$ V, G3. Integer x = new Integer(5);* T( x' F8 A7 ~6 S
4. Integer y = new Integer(5);
8 {4 a0 n7 G, g2 I5. Integer z = x;
3 h- t; o8 [. T* L% z' ~) E9 l) l, C6. if ( ______ ); U! @4 E, j4 b/ U6 s
7. System.out.println("true"); t2 \" ^$ k1 B, s
8. }" l3 X' S6 q' c$ \9 Z; B
9. }
) \! R4 X/ a. E ?0 i; n2 [以下哪个选项填入第6行后,不能输出true:# V. E/ t; E5 m" Z2 `2 F- r
A. x==z
: N" Y$ o" E- hB. x==y8 X: ]7 J, _/ b: r. P
C. y.equals(z)
" \# m/ j* {) i4 rD. x.equals(y)
0 W. S: d& J' Q6. 读程序(双选):
% C6 @% z: t l/ L1. public class Declare {
/ \/ y9 H; L9 p- H: A2.+ [. K. s1 D! m j0 I+ y3 G/ e: B
3. public static void main(String [] args) {
0 i. {$ l6 L/ }. u! ^, y& T4.9 {5 H B2 n5 l* u6 N
5. System.out.println("The variable is " + x);
: v4 ^7 W+ Y% b% `" `3 e6. }
8 Q4 ~4 x* R. B# Q7. }
; y, F: d; g5 x [. A. \以下哪个选项中的代码可以使程序编译通过
' E x4 k8 t! t; a ?9 rA. 把“int x;”放在程序的第2行$ L' R6 u, t# X" Z6 U
B. 把“int x;”放在程序的第4行7 N3 Y& L4 d" n/ l& n3 T
C. 把“int x=5;”放在程序的第2行
7 \/ f5 U4 o( m7 b) \+ wD. 把“int x=5;”放在程序的第4行
( q" c+ w9 [9 k$ F3 `. @E. 把“static int x;”放在程序的第2行7 `0 S% a& K8 ^1 ~( q: s$ V
1 g: f4 P S4 U. O( _" D- B) U
{2 B0 j3 O+ H0 i. @* z7 n& q
- y0 J0 ?/ h# {7. 读程序(双选):6 a# w3 y Q T. }" P
1. public class Child extends Parent{
; X9 H3 n8 ?# e5 t) I2 O8 b2. int a, b, c;
; S. ]( p# m. O7 c3. public Child(int x, int y) {
1 @& c% `% R; ~- E# n4. a = x; b = y;
3 j: j, H* ?: P5 c$ j5 Y5 z8 n: Q5. }
& D* y' i1 Y% G/ I& O1 S( l6. public Child(int x) {
" Z, X% N8 ^: c0 R( ]7. super(x);
c4 o. ?4 M- F$ G1 r* z8. }
, [, @7 a- h' E% m# Q* v# b9. }
! R( K. K' Z. E. i* R4 C为了能使该类编译通过,下面那个构建器必须出现在父类中:
+ G. }+ r4 j3 T/ FA. public Parent(int m,int n)( u, z1 d6 a9 U7 K* j, k* E0 A/ k
B.public Parent(int m)6 w4 T% I: I z2 s* A
C.public Parent()
% t& H' t$ {( X/ S4 {" g& y4 yD. public Parent(int m,int n, int o)
) Z$ F3 f" O+ r" E; Z8. 读程序:
7 [1 A6 y. Y6 o: k1. public class Derive extends Base{
" o8 u( A6 {& Q0 c4 m+ V2. public static void main(String argv[]){7 b5 s! T* }6 H9 o% w: B
3. Derive a = new Derive();* T% ^ ~; v$ y7 @4 G- X
4. a.method2();$ x+ p8 n4 m) q- L# N" e
5. }0 y, P, T- b9 y% ?( R
6. public void method1(){
8 J* O# w/ M( O! P0 f7. System.out.println("method 1");
3 V& B) ]5 c G( R0 b( W5 m( d8. }
0 p) L1 I3 c/ K( s# N- x# ?% S9. public void method2(){
9 K3 z3 o$ }4 l10. method1();
5 E/ }% o. `) n3 O: n5 A) U11. }' L/ \- Y7 D; T4 E) S! h
12. }
- E' Z4 o6 r: E: \, N) j5 k13. abstract class Base{
9 w: k6 J+ Z( U14. abstract public void method1();8 [. L6 m4 C( G
15. public void method3(){# B, m9 b9 o" ?- Q' x6 h [6 L; o- j
16. System.out.println("method 3");
0 M8 d9 |* O9 G3 C( r$ I; I6 M17. }
$ ^, |% I& L' C3 `( n+ Z}
6 M9 _) [* k" D当编译和运行该类时,将出现什么:
. v, ?& D* u8 u% nA. 程序输出“method 1”9 L" \3 l1 o- M) H
B. 程序输出“method 3”; ^+ w h2 u+ i
C. 程序因为第15行而出现编译错误5 F6 m9 G3 A6 {3 f/ z# p- `- K- w k
D. 程序因为第15行而出现运行错误
m3 N& o! z- S, x% _* P9. 以下哪个接口的定义是合法的:+ k% U( c D5 [7 o9 b
A. public interface A {int a();}
3 u7 j( w: ?4 W) VB. public interface B implements A {} k" h% K# o N5 o9 C
C. interface C {int a;}5 t3 N7 a$ ?, m! s1 ~
D. private interface D {}2 z. B5 \8 I4 k1 L9 b$ s4 W
10. 读程序:. C9 w7 K( V; A/ R3 Q
1. //File SuperClass.java4 S1 x% R/ M# Y4 B5 V/ L: `% V
2. package MyPackage;
& E$ b5 W& x% ], ?2 t' v# s3. class SuperClass{
W- v/ W) C1 {- o& r8 J4. void myMethod(){
; i/ ?& S, r5 P5. System.out.println("SuperClass");
( C8 x4 _% s$ a6 B/ z6. }
5 z! n6 o! U* Q8 T7. }
2 W) c( m u- ?+ T4 T+ a8. //File SubClass.java
+ z7 m2 l1 d4 w ` _9. public class SubClass extends SuperClass{
1 w* f3 N% O5 l$ z6 I10. public static void main(String[] args) {! c0 t, e4 z' `0 c5 E: X
11. myMethod();
" O$ L0 b! T* a7 l12. }! ^. b) k$ L9 M* l# c
13. }8 k. P, ]/ {& ?$ g) s
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
4 X: T9 P8 _- B# L* EA. 两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”/ P# ~0 v, q/ ~
B. 两个类都回出现编译时错误
( I% y. \5 c F% x, aC. 两个类都可以编译通过,但SubClass会在运行时出现运行时错误, h/ k- p; u" N$ ^
D. SuperClass.java可以编译通过,但SunClass会出现一个编译错误
$ N; j$ R& w/ c3 b; L$ f; _9 j3 P11. 读程序:
* B4 g w! I8 D- s5 Y' F6 Z1. public class Test{
& I, w) M! U% a8 O' F3 A2. public static void main(String args[]){8 @6 m) l) u2 {7 d
3. int[] i = new int[5];
' G& @! {! R1 ]: S0 a4. System.out.println(i[5]);% q- l3 o8 u8 j4 `9 T
5. }- B& Z+ R! {$ P' q* A
6. }
0 o3 v! Q k, y& m& F( B0 a( d当编译和运行该类时,会:
5 z9 y# b3 _( H* ~; qA. 出现编译时错误
, P6 T2 K0 L: f3 P0 c% z" dB. 出现运行时错误. A! z1 C n. K2 I3 o! }! h6 l- q
C. 输出0; I1 x# R- d6 Y
D. 输出null) _' J5 I' _: Y0 O7 ?9 c7 Q
12. 以下哪个选项是正确的数组声明或初始化:3 s, S0 S/ f8 `4 z" C; U* g
A. Array sizes = new Array(4);0 r3 z. {* u2 n& U c
B. double [] sizes = {1, 2, 3, 4};
0 k0 O% Y1 K% MC. int [4] sizes;
' ?9 G6 h/ a. x9 f- v8 J8 {D. long sizes [] = new [4] long;! E; A9 g' E: _6 Y4 [/ r; k
13. 读程序:6 N- _3 `9 q, c" [$ d7 B$ S5 w$ `- A
1. public class Initialize{
% F2 j& K+ V" y5 ~5 l1 o2. int x = 200;( g+ m f3 [9 d
3. static {1 a. U2 [8 a6 l$ \. A- y" g
4. int x = 100;
& R, p6 N8 `6 a6 c: X5. }
S! z A( }4 F/ j) O4 e6. public static void main(String[] args){& } T3 |; r @ N& E8 O
7. Initialize init = new Initialize();, {* j! q4 F2 b0 }6 ?
8. System.out.println(init.x);7 x- n. m6 @' e, M5 O2 }) r) s. U
9. }
+ R' M8 s- F! U p; t' }10. }
0 {8 Y9 D2 Z# [当编译和运行该类时:
% ?9 o$ X4 ~$ WA. 程序因为第3行产生一个编译错误
5 E, e9 w4 p9 Q* jB. 程序因为第4行产生一个运行时错误
" |2 y' g- p# Y7 W% BC. 程序输出100
2 R# Q% d$ d- P* z; n* R0 q1 DD. 程序输出2006 H# F6 m- a. @) l
14. 读程序:
; p2 d4 t: m# w1 l B* p1. public int abcd( char x) {" t) z; J( d$ h1 a
2. if ( x <= 'M' ) {
" H& V) g; p C! w3. if ( x == 'D')
% v1 z# x, n1 h4. return 2;
) x' l2 s' m f( E/ ^, Q5. return 1;: ^" g$ `3 N! l/ g- O
6. }5 J; B7 c. I4 \! J2 J. v
7. else if( x == 'S') return 3;: \! M2 E2 ^% V6 Z4 q# b6 P
8. else if( x == 'U') return 4;4 }2 A* r, ?- c5 O
9. return 0;7 M/ y1 C3 w/ k$ z' o
10. }
8 Z! ]3 I4 s3 F0 a) P; Q- V在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
$ B! `" r) G' `& n: T, z# c* `0 y$ _A.‘X’
$ ?* ^; J5 m! tB. ‘A’* P# S& c4 R; P# G* z1 a5 m
C.‘D’& o( O f" F$ r
D.‘Z’
5 |: H: H; m& i6 x( w; K- a15. 读程序:
4 J( Y' T. b2 } y1. class TryTest {
4 `, O6 J; L x9 H* z# z) C ^2. public static void main(String[] args) {4 K, b/ h6 g% O, {% \5 C- W8 ]6 G
3. try{
# o2 V% U; j8 ^9 A3 g6 Q7 O; O4. System.exit(0);! @0 q, w7 e) J4 m4 K
5. }/ j* ]5 E0 w& q7 @/ r
6. finally {
. ?. E0 q5 n& y# `) ~7. System.out.println("Finally");3 u/ C7 g4 y3 b/ Q1 W3 c ?
8. }
* p% Q3 k) D) |& {9. }
* c: I( q. k; J& k8 v10. }* [/ u; i9 F7 Q
当编译和运行该类时,将:. M9 }/ E+ J+ F
A.程序因为第4行出现编译错误
5 A) I" ^5 s! _# n, _, u ~B.程序因为第4行出现运行时错误3 L6 z3 K4 v( C- y, z4 z
C.程序因为第6行出现编译错误
$ t+ w% m! Y' W ID.程序因为第6行出现运行时错误4 t( J( E' ^2 b* Z( o. l( s3 ^
E.程序输出“Finally”
$ y% y- r% \- Z% M- wF.程序可以运行,但什么也不打印
/ w- z i. F$ ?) o: n. B- ^* D$ d/ g/ B
16. Given the following variable declarations:! V( n6 n3 U& u" H: s+ `$ {" F3 ~0 z" Z9 U
Boolean b1 = new Boolean(true);" |. u7 W) n$ Q' C9 P
Boolean b2 = new Boolean(true);6 f! R& I" J& M8 H
Which expression is a legal Java expression that returns true? & \1 f- Z& V; G" a( e5 H' F* c/ j" r
A. b1==b2
* p! ]# p8 ]- C1 ]& @: ZB. b1.equals(b2)6 J3 N( \# X# j. {. y7 ^( i1 u _
C. b1&&b2
; @/ |$ K# q& r8 W0 VD. b1||b29 t6 K9 F8 V2 Z. D5 I6 L$ k
E. b1&b2
$ _ q% V' t( iF. b1|b21 g4 d( b0 Z6 L0 i A8 r2 k
17. Given: ( D2 X/ L- Y: H* y3 q9 Q) ^
1. public class Employee {
2 [* ]& ^" u* u4 \$ ?$ `2. 6 S; x! m. S0 L
3. }
- r. n/ d1 [4 g: c) _4.
: n/ \! \# p& G: C9 i( f5. class Manager extends Employee{1 v% e) y( m8 G% P6 U
6. }
& N/ X4 e' W' q9 t5 l: s) W& GWhat is the relationship between Employee and the Manager?
& C$ k& O/ l c0 _/ U. Q# NA. has a( ~ E0 T5 @9 d
B. is a
7 j6 m& V" |4 v% z& t" z$ j0 R7 dC. both has a and is a n2 Q0 d- d! t1 j' Z
D. neither has a nor is a, B# d! |) t' l1 D b' ]" n, s4 j7 C
18. Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
& i( {& s: O9 ]A. BorderLayout" D; x. R, t9 M( ], m0 t( _
B. FlowLayout; m/ C# K% X/ @* L7 [( x! }% w2 ?
C. CardLayout
/ C4 t1 S5 `0 Z5 o2 v- T lD. GridLayout( c/ a. f: \4 F" Z7 I+ j ~) N
19. Which of the following AWT components can generate an ActionEvent?
f; _' U R3 F, I% U0 R: w+ L* ~% `A. java.awt.Button
" {: S9 e% I2 a$ _B. java.awt.Panel! L: T; U$ m8 i8 T
C. java.awt.Canvas, X6 U: S3 R4 U, U1 q
D. java.awt.Scrollbar
5 u( r3 `7 u0 J. D8 v' |$ [ j20. What kind of Stream is the System.out object?1 B& F: x( E- e' u4 ?7 S3 T4 ?" R
A. java.io.PrintStream
6 v! H. m0 g k2 \6 YB. java.io.TerminalStream# n$ O1 J5 ^+ n& ?: t+ k2 J. J
C. java.io.FileWriter5 E" [9 c- }% ]. ~- c" n
D. java.io.FileWriter* D5 L x- K+ l% L% x
21. Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)
3 }1 ~* U5 t7 H1 q! Y% LA. java.awt.event.FocusEvent! M% p; x! u7 ?5 p% _/ |. [) Q
B. java.awt.event.KeyEvent
# }" Y z+ G9 M. H: ^* U9 mC. java.awt.event.ItemEvent
0 i- `( V4 H4 pD. java.awt.event.ActionEvent
0 j% }5 q4 z+ \( i9 U6 b22. Which of the following methods are static methods of the Thread class?(双选)
# K( Z/ X2 t% J& l* q2 @/ k9 M, cA. sleep(ling time)
$ k8 g8 C3 A' j3 q: U4 cB. yield()
1 [1 S, L) |! ?4 |5 OC. wait()
0 |) t4 ]% {! _7 n5 `# \D. notify()
& b: }1 t2 j% r! f; T7 B; i8 u23. Which method do you have to define if you implement the Runnable interface?
& s, Y, r; b( f. tA. run()* p+ I( ^& i: h+ s: W
B. runnable()0 U* W4 z, j$ @) w
C. start()
2 B$ l5 t9 F4 [+ \% xD. init()* ~: n' w- v/ ~! w* E' x" P
E. main()
; f7 H F2 N3 f1 ?24. Given:: a& y& M! K' P# L
1. class MyThread extends Thread {
$ q3 q- `1 a8 z; q2.
( L+ d5 ] X2 |; u) E3. public static void main(String [] args) {9 c& f& t( M( u# Z9 v R- B
4. MyThread t = new MyThread();
6 `" X/ ~4 m# g- H) z7 I( M5. t.run();! F1 \: ^4 H! w: O4 ~
6. }
" o& F! _, d- R8 O4 Z+ \7.
6 Y, A O( U) `8. public void run() {
$ s7 \0 z+ _8 l [# B8 o/ e* N7 @* d9. for(int i=1 ; i<3 ; ++i) {( k& O7 _5 K. |) B
10. System.out.print(i + "..");
& {0 n) y- m. \; {9 g) u11. }
- a& {* I0 W) p( q, N% r% s3 {12. }
& s+ `- c% w( a( z13. }: Q' Q* @4 s! H5 z7 B
What is the result of this code?C7 }" f% g$ U' U2 P; _- {; _% B
A. This code will not compile due to line 42 |7 Y6 f0 J( \7 C$ c
B. This code will not compile due to line 5
& n9 ^/ W2 x4 y9 O6 UC. 1..2..
& _* `% M$ [* S( q1 y7 u1 jD. 1..2..3.." P4 O* t b2 m9 N' e% @+ v
25. Given a local inner class defined inside a method code block, which of the following statements is correct?
7 ~9 X5 [0 L% d* u0 \) u5 ~A. Any variables declared locally within the method can be accessed by the inner class5 } V9 F% D8 o9 e0 Y& z
B. Only static variables in the enclosing class can be accessed by the inner class$ e6 M Z' E% I" h; J' R
C. Only local variables declared final can be accessed by the inner class+ P$ e) E: i K
D. Only static variables declared locally can be accessed by the inner class.
/ T8 q: e- S& G) m* }! C- o* \
' [9 M% u- e, t
0 u* Y( C. e) T# S' Q& w3 U
$ j( |( a" n+ b% D" C6 w0 v26.public class SychTest{
) d& U& b- D* y private int x; 9 S( ]* h: B- L& r, k
private int y; O ~& A% C @+ H ^& o: D4 f
public void setX(int i){ x=i;} / @& R$ |" b3 Q; \" d% V- P
public void setY(int i){y=i;}
* K) d& ?# t) Z+ k- L# E* s public Synchronized void setXY(int i){
5 V( d5 e0 N5 D Q, A7 ]7 n setX(i); / t) S7 }; C% |, u( `; I; T
setY(i);
4 z7 w5 D2 T" ~- ~5 [ } ' {$ R3 a' Z5 b6 }$ m
public Synchronized boolean check(){ 6 |# v+ E* B7 n
return x!=y;
* `+ \+ l8 v$ P# b$ y }
! W5 \/ \2 `2 a8 h+ c2 a }
( C% K+ j0 r$ n1 c& B Under which conditions will check() return true when called from a different class?
; E/ k, C5 C6 u! v& U0 S A.check() can never return true. / D4 c9 X/ T: b+ u: E+ w
B.check() can return true when setXY is callled by multiple threads.
$ U0 G! P- C# e6 z# {8 S C.check() can return true when multiple threads call setX and setY separately.
' j3 g7 _) Q# h0 C: I+ u# Y D.check() can only return true if SychTest is changed allow x and y to be set separately.
; x- \" R& j- G; R
5 l. R# c5 F6 B, o+ h" S; @27. 1)public class X implements Runnable{ % F2 s( V% I3 z6 ~1 }, P5 K
2)private int x; 9 \- }, \4 e$ a, f
3)private int y;
7 p" z& B7 p+ \9 j 4)public static void main(String[] args){ ) @: |* R8 Z( S. j
5) X that =new X();
- q& T, ~8 H$ ~4 b- a" _ 6) (new Thread(that)).start();
4 E6 f% w! F5 V6 p* G 7) (new Thread(that)).start(); 3 b# m0 R; j& ^* g3 C+ s* e6 w
}
" g2 T7 S, q! s+ \# j 9) public synchronized void run(){
$ }) J9 M+ m- @6 X: Q0 O; \ 10) for(;;){
! h. @8 ]1 z) E; Y) D( l 11) x++;
# o, L6 T$ O1 F" r 12) Y++;
3 K$ [2 m( j7 B5 q A 13) System.out.println("x="+x+",y="+y);
2 |+ s: L$ T4 O1 j# {/ ^ 14) }
1 a ^& P, S* J3 u" {* q 15) }
8 j. M3 U/ Q: o# J! b9 f. j 16) } ! e+ N& H- g5 X" p
what is the result?
; j, z* H: D( d A.compile error at line 6
9 y5 `8 a$ o3 a B.the program prints pairs of values for x and y that are
! j$ t8 c0 u7 ^ always the same on the same time ; C* Y8 }8 Z" q' U! j
. |0 J) @! ?% T% Q# b. B2 j% U- C2 z28.class A implements Runnable{ / d: f3 k0 w3 Q& P
int i;
& Y: a/ Y- {8 ~ public void run(){ 1 }# j! G" A' y
try{
' m |8 C- `) e- C Thread.sleep(5000);
+ \1 l6 Z+ c1 n8 f i=10;
( X. f4 e# F/ L1 p9 @9 D7 t. f* S }catch(InterruptException e){} 0 j2 j& ~* y2 }- b, E0 _4 d
} 5 H' i1 C8 |5 _
}
6 w& j8 ]2 m: v0 [. f public static void main(String[] args){
- V( X6 Z% r. @ try{ ; ?3 {. Z$ B$ \# Y7 n. ?% Z" {
A a=new A();
8 _ @' y: `! T! v3 |+ i- e# U- Q Thread t=new Thread(a); , E: }0 m! Y9 I; R
t.start();
. w* Q+ _2 J. o P: ?/ { 17) " [# e2 z' u+ I: }
int j=a.i;
6 E' K' ^, n! d+ Q1 V/ O 19)
' @+ \1 t! n k2 p }catch(Exception e){}
% s( M3 M8 {2 D4 ~& a }
( \6 n. v! E; R) J0 a' O# t$ J6 f7 Y }
# Z3 _2 O% c9 ?1 `8 ^5 Q what be added at line line 17, ensure j=10 at line 19? / V* [+ \8 m) h7 F$ S
A. a.wait(); B. t.wait(); C. t.join(); D.t.yield(); D4 t& I: s" u! V* v. k
E.t.notify(); F. a.notify(); G.t.interrupt();
' r$ l% @3 `7 r# r8 ^3 D29.1)public class X{ 5 h# T) j1 I* o6 m9 l6 G2 `
2) public static void main(String[] args){
' o. ~" o# D0 p- o. H 3) String foo="ABCDE"; : o, j5 z$ }0 K9 \# N4 S
4) foo.substring(3);
" ^+ j- e, l3 d7 o$ l& Y 5) foo.concat("XYZ"); i$ `$ Z* x4 |# m* L) x/ [+ ~
6) } $ y. V. r& z$ F2 x# X2 r# o
7) } ; f- M+ w7 L C- ?9 s5 B) W
what is the value of foo at line 6? 1 [/ |7 Z0 e8 L, A W
30. public class Test{
' H: S; G' i/ I. W* x. x public static void main(String[] args){
, ]4 }) L. ]- k9 f StringBuffer a=new StringBuffer("A");
, T/ K) o3 g/ U- C8 Z, l- H4 e StringBuffer b=new StringBuffer("B"); 4 ~2 L' O8 v% S& u
operate(a,b); * X/ L) r! L/ x( ?$ h& R! J
System.out.pintln(a+","+b); ; \3 {0 R% S% u9 p, P
} - I' s0 A) B7 m/ E1 |& ^% f% R
public static void operate(StringBuffer x, StringBuffer y){ : B: m5 Y1 [5 e# D w
x.append(y);
# h: U9 @ |5 q0 v/ j, ^5 L0 N y=x; : K3 b$ [- P% M) E
}
; h9 P2 z; Q% |0 W+ v' [: ]' A } - P( h- H5 Q- J# v0 c, c- V
what is the output? |