Sample TextJava培训考题7 ~% ^ ^) `5 @5 P" S# T7 p0 J4 p
1. 给出以下程序:/ w, N' ]& H! h
1. public class Colors {5 r! H! l8 x/ g$ ]
2. public static void main(String args[]) {% B6 ^& D4 e+ j# P5 o3 z9 {
3. int n = 1;' A4 }- ^) A1 H W- V) R, `
4. System.out.println("The Color is " + args[n]);' W8 @: Q" b6 k: n9 r0 D
5. }, l$ B. z0 s) k
6. }
# A, n) d( }* F6 n- u! V: n假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”
. Z0 n5 P5 `$ E& Z4 i( x; j3 OA. Colors red green blue yellow
9 L$ B) d0 q Q% C P* ^B. java Colors blue green red yellow
5 Z' A9 n; J$ B" fC. java Colors green blue red yellow
* H- t6 P! R5 j! PD. java Colors.class blue green red yellow3 A7 }- t; b/ s+ g7 y* W
E. java Colors.class green blue red yellow
3 ~' T" @0 a3 ?$ Z3 y3 u6 \2. 读程序:$ {' n1 t8 @0 D8 b' {
1. public class Test{8 Y9 }& {/ @1 P! t
2. public static void main(String args[]){& k# U, z: X: b5 A
3. char c = '\u0009';2 S7 K. c7 L1 C" G$ ` b4 {
4. if( c == 0x0009L)
8 n7 L) r# M4 L5 e. _5. System.out.println("Equal");6 ^6 s! x9 y5 O/ }* M
6. else System.out.println("Not Equal");% s" B9 Q6 T- {3 s! p
7. }5 l) e c/ o' ]( h4 _% ^$ ?1 K
8. }
$ ^ ]' X7 W$ T! Y- h" i当编译和运行该类时,将会发生什么:
: x6 a. G. n1 E- X' ~, x' q$ F1 }A. 程序因为第4行将出现一个编译错误3 _8 {8 \' y/ `$ |: z8 v. G x0 o
B. 程序因为第4行将出现一个运行错误" ?& w- `) [7 t" S2 O4 o6 V6 [
C. 程序因为第3行将出现一个编译错
R. O- c# s: M" u2 |D. 程序输出”Equal"
+ y1 T7 k" n, A" j* s4 }! s, mE. 程序输出"Not Equal”
, t/ d+ h5 e: n- c- D8 y/ r' s6 m3. 读程序:; x! k1 k* Q& O% z
1. public class StrEq{( }; P# D; d, K3 F& i
2. private StrEq(){
7 P3 k4 T# R7 @9 l' L7 T3. String s = "Bob";& Y& Y1 M: w1 Q
4. String s2 = new String("Bob");4 g a; I: t6 k
5. if(s == s2){) a" _2 S* B9 Z. f4 p9 m; h
6. System.out.println("Equal");
( T5 ]" i# A+ G/ \$ C) V7. }
$ V& X) x8 I) R1 p; a8 h8. else{
5 h5 U& N3 R+ l% E% v9. System.out.println("Not equal");1 i/ r# z7 F4 s ~% A
10. }8 ]) X9 _" T! u! A9 T
11. }
; s2 d! y+ a- W" w7 ^/ N12. public static void main(String args[]){
# f# B. Y& X9 o8 U13. StrEq s = new StrEq();
6 Q4 M) F+ y1 l# }: [: [8 w' v4 r" k14. }
: A8 ^8 N0 ^& m15. }
9 D& T0 r0 a6 e, y当编译和运行该类时,将会发生什么:6 g5 b' p9 s* P$ \; q$ n& p
A. 程序能够编译,并且输出“Equal”) |2 _8 h- P0 W/ V j% [- o: ]
B. 程序能够编译,并且输出“Not equal”4 C: ~/ b! p. f7 [0 ]. L9 u* g3 N
C. 程序因为第2行导致一个运行时错误2 Z3 }' w/ W- O
D. 程序因为第2行导致一个编译错误
+ t m q q8 K3 L4. 以下那个赋值是非法的:- R& D0 E6 i% e0 {
A. long test = 012;7 n0 }6 S; V/ l8 i) G+ ~
B. float b = -412; J- ~* n- j) E
C. int other = (int )true;
) a3 _# p7 b3 B( |D. double d = 0x12345678;$ {; Q, I- b# I( k: o# ?
E. short s = 10;
M8 K, K% A& o( v! W2 L5. 读程序:! p, y; p) J. V" ]
1. class CompareString{
7 v: S# b5 X# ?) K; P3 D7 h2. public static void main(String[] args) {7 R( f# x3 G# j' ]4 x9 r
3. Integer x = new Integer(5);8 d! Y$ x) J; e& n) t4 ^$ ~
4. Integer y = new Integer(5);
6 f2 b! d& O2 N0 ^, z$ X% S' b- b4 `5. Integer z = x;2 { j" Y% P- P0 C! D
6. if ( ______ )8 Q; l4 K/ X7 J# a
7. System.out.println("true");9 S$ K5 x6 H$ O- W$ z
8. }$ f8 ` w- U+ P' K
9. }
% k5 H( j& p2 ]4 u以下哪个选项填入第6行后,不能输出true:) z. q( W- c4 E
A. x==z
8 Z# I6 @( d& u" cB. x==y+ t! i& A- f U2 R4 |5 h
C. y.equals(z)6 [% E* R6 i- j2 A2 c Z
D. x.equals(y)& e# \3 W7 l+ g4 _ O
6. 读程序(双选):% G1 J3 @3 ?- _+ t- X8 c
1. public class Declare {2 A* u% P6 }+ I$ c8 U" z
2.
+ n9 j+ N' ^8 U; h: P2 b5 g3. public static void main(String [] args) {/ g1 t' s9 j6 Y: J E7 k8 B
4.8 d5 C+ y$ B/ ~7 X2 `, B2 Y0 E% y
5. System.out.println("The variable is " + x);% v4 L: n1 o' o
6. }
2 k# M9 a$ W; ^7. }
8 A- V+ \% ~' T( \8 ?, R- O以下哪个选项中的代码可以使程序编译通过5 Y5 l+ P* k8 y
A. 把“int x;”放在程序的第2行7 |7 ^$ ~% J% |# v! d: j. p
B. 把“int x;”放在程序的第4行
8 c( z+ ^8 F2 q" }, E7 u6 aC. 把“int x=5;”放在程序的第2行4 r2 l* d3 q3 m- g; G* y
D. 把“int x=5;”放在程序的第4行# H0 I. Z p/ e$ X& ~5 Y5 H
E. 把“static int x;”放在程序的第2行
! i$ }: j1 `6 e, y" V u$ `3 F" L& z% n: S- H5 z0 p
. t! D5 j! u- R: a3 L4 w' e: k
! X2 T; v9 k6 z( Z* e7. 读程序(双选):
, _5 F: h2 B6 ], n4 T* ?; N. d) U0 ]1. public class Child extends Parent{
5 l; i0 E5 S( H( S# {% x3 x6 M1 y9 v2. int a, b, c;/ |" [ c" U; ~7 d' i( p7 w
3. public Child(int x, int y) {
" d, q/ k* x( d0 g4. a = x; b = y;
1 n. ]) g4 ?9 g+ U5 E$ M; }) [5. }0 f) {( K1 {* R! v& n
6. public Child(int x) {
' c1 a, {$ ]/ D; B/ [1 Q7. super(x);
% n5 m% a" Q8 O! M- b8. }
8 b0 w0 T3 f3 T$ ]9. }
4 c9 {) X$ ^1 W& @9 |为了能使该类编译通过,下面那个构建器必须出现在父类中:8 o; p& F$ D1 U: q
A. public Parent(int m,int n)
; {. w, q3 [( PB.public Parent(int m)
4 {7 L. k; x' ~- b$ v7 XC.public Parent()
4 w, }8 e' A8 u1 l* q; gD. public Parent(int m,int n, int o)& U8 D8 f" H7 ^/ k
8. 读程序:
8 {! k! j# L, |6 m! B1. public class Derive extends Base{4 ~4 ?+ q3 x* M, y+ |: n' _
2. public static void main(String argv[]){% a0 ]8 L8 P( E6 K. Q
3. Derive a = new Derive();
6 a' Y; Q$ v( J0 D( R! h7 i4. a.method2();* |5 S+ L* [ u/ F8 G
5. }5 T6 k( x6 V8 Z) z$ ~4 [3 L# K
6. public void method1(){
+ D7 E1 G" S+ [: ?/ o* I) |7. System.out.println("method 1");) q' _9 E8 O+ g: u2 q
8. } 2 v k" H. B- k
9. public void method2(){. S; p& y& C% Y1 p7 _
10. method1(); 1 ?- g$ H9 r8 q9 Q. i
11. }
( L/ s* U* ]' s3 m8 G6 G12. }: g) C/ h' M a
13. abstract class Base{4 X% W) V9 X) N, W5 q5 {% s: N
14. abstract public void method1(); L. ?+ F( d' D+ A. _, E+ ~7 O$ @
15. public void method3(){" X4 Z* ` g) p2 D& z
16. System.out.println("method 3");; |4 p' }/ U* [- g+ \7 o
17. }; h+ u% J9 C. B. J
}
1 @% f+ }( b E; N: i2 [2 d当编译和运行该类时,将出现什么:( s6 r4 d( [, @; o9 r2 l
A. 程序输出“method 1”) L; n% s" L3 W
B. 程序输出“method 3”1 H+ S; d1 c! U) p" o
C. 程序因为第15行而出现编译错误. e3 i. b& G- e \0 M
D. 程序因为第15行而出现运行错误+ p- h- O" s/ {5 R2 x' L4 J
9. 以下哪个接口的定义是合法的:/ c8 i9 A* a1 r5 y j! ~ l
A. public interface A {int a();}# b) G* j% I/ d, Q
B. public interface B implements A {}0 ]5 ]/ C& N; B8 h
C. interface C {int a;}4 L3 ?* y$ V j" M3 _
D. private interface D {}
1 z+ [* ]: m' L x! c10. 读程序:& p" Y0 b5 D" ~0 @2 S
1. //File SuperClass.java
, `- _) ]9 Y$ z8 t. P2. package MyPackage;) q: P% V: _# h, L
3. class SuperClass{6 [! W0 \3 s6 X1 r
4. void myMethod(){1 b7 g% B0 E% f+ c. z$ N4 B
5. System.out.println("SuperClass");# v: T, ^' ~( C/ I+ S# @6 ]+ F
6. }
) f1 [4 W9 y$ S1 u8 z6 e7. }
' r1 l3 t' Z+ F6 Q4 e/ ~8 ~8. //File SubClass.java0 W7 U% C" \5 ?7 Q
9. public class SubClass extends SuperClass{5 x8 c2 P' Q9 C: R; b0 k
10. public static void main(String[] args) {
& p/ D+ J! d# _11. myMethod();
3 n& F2 h; w5 ^6 p' o% o) ?12. }7 S; b% M* F8 K% O8 X0 D
13. }
0 I) n7 U z; }8 q0 `当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
: W+ A+ O( |- o; e, {A. 两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
9 N8 g1 v! V) i# L; BB. 两个类都回出现编译时错误
' K6 r/ l f% j* S j) A: }( FC. 两个类都可以编译通过,但SubClass会在运行时出现运行时错误
: }+ ^6 n1 q+ |1 P# mD. SuperClass.java可以编译通过,但SunClass会出现一个编译错误
: e' w* n7 J% a8 D0 U f5 C% k$ ^11. 读程序:+ I; k+ X9 p' D" E
1. public class Test{
8 t6 Q9 s' H0 C2. public static void main(String args[]){* C# y- P8 U& h9 i
3. int[] i = new int[5];
! m/ {* j* z; j% A' A9 E4. System.out.println(i[5]);4 \4 l w2 l1 Y+ w2 u
5. }
2 V- i1 k0 E2 s6 H7 X6. }
: l7 Z$ s5 J% F- d. n3 A当编译和运行该类时,会:; c* C t& w' |6 u$ ~0 G% k
A. 出现编译时错误: G, B0 G0 T7 b" A& N
B. 出现运行时错误2 I' j8 l! r/ e" p+ I
C. 输出0; ]& d; E2 n* Z+ h, }5 {
D. 输出null
5 n5 L3 J; S6 b2 f12. 以下哪个选项是正确的数组声明或初始化:
3 R5 P1 `6 r0 @6 ?) Q( LA. Array sizes = new Array(4);& M% y4 x, b8 e7 z. J, \
B. double [] sizes = {1, 2, 3, 4};
5 e: T7 D( ^+ u* _# D( AC. int [4] sizes;6 T9 I7 F$ P6 t$ i
D. long sizes [] = new [4] long;
% _8 b- B, g2 B" J( b* s8 P# I13. 读程序:
, X& H5 h) Q4 c& n m1. public class Initialize{
/ ?% c) i1 Y+ x* |* c/ A2. int x = 200;
8 A0 F4 G4 t5 D6 z: p3. static {
7 K' p5 q9 Y+ G& _9 l" L5 }/ r7 ^4. int x = 100;9 J# s" A9 X" p- W# p u! C
5. }
* K$ P+ T7 B w7 e" L: h/ p6. public static void main(String[] args){0 B2 X# M; N5 k$ p6 E% T: H/ t" f8 U- o
7. Initialize init = new Initialize();$ v: x" H3 o0 L# @% }( I
8. System.out.println(init.x);# ^# |6 e C. L$ B( M
9. }* L0 F1 `# u) K" H V. W
10. }
" C9 t, w$ U- ~0 K) p$ e* Z Q当编译和运行该类时:" Q3 }# w' f5 ^
A. 程序因为第3行产生一个编译错误
& p2 f4 ~7 ^' f; t' C+ t f0 ZB. 程序因为第4行产生一个运行时错误
7 A3 t1 `3 d( tC. 程序输出100
3 o0 \' S# m5 P" r6 @/ TD. 程序输出200: D( ~" s1 z# N
14. 读程序:, j% [( |6 c8 N7 V+ J
1. public int abcd( char x) {4 ~! C9 b& A: s
2. if ( x <= 'M' ) {
: p3 }+ I1 m5 j* D3. if ( x == 'D') ' J9 t8 m% J6 c! G7 @
4. return 2;
% z. e5 l* ^6 A4 A" [ @# {5. return 1;' {& l b. `, K) Z
6. }
( W$ W2 x# N& L3 h( j4 G7. else if( x == 'S') return 3;2 A3 l+ U: v' @0 g$ u
8. else if( x == 'U') return 4;' d. Z1 G+ ~: w* Z
9. return 0;
" q5 }& j6 ?# T) B* h( ~10. }! p. ^. [9 \. X
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1" C& |( e+ U/ @: j& ~4 s+ Y! H
A.‘X’% ]" t) o# f7 u7 V
B. ‘A’4 X- R7 U W7 H& O+ ~9 ]$ K
C.‘D’ k5 J5 v& `5 h
D.‘Z’
6 X6 h4 m( F A5 \+ S" c# I15. 读程序:
6 u. {% k9 c! X7 G: i+ ]1. class TryTest {
. ^9 j @8 P$ S1 ]: }2. public static void main(String[] args) {
& M9 a2 w. a% Q( y$ o2 k3. try{. Q$ @5 p [" p: @) t
4. System.exit(0);
, s; W/ K0 P4 M5. }
6 y+ C' E- G: {0 O0 A) _6. finally {
# S' A2 S1 V% m7. System.out.println("Finally");" s6 k0 t$ \- c4 K. {+ C
8. }1 X U" h2 ~5 M% q. `' J6 L1 M
9. }2 {8 k% f D9 H- L
10. }5 u: i' @9 r& |) _- M g9 I. Q' l# j
当编译和运行该类时,将:
8 w3 l7 T4 e- F yA.程序因为第4行出现编译错误
7 U9 S( k" L2 h. I1 ]: WB.程序因为第4行出现运行时错误3 I: c9 n* C$ g4 {
C.程序因为第6行出现编译错误7 n" v: S5 J7 y5 _5 @
D.程序因为第6行出现运行时错误
( n8 `6 n' k+ O) fE.程序输出“Finally”4 ?4 d/ G% A' m9 A; b+ q2 I/ F4 a
F.程序可以运行,但什么也不打印# J1 J9 b. h& g* [. \
5 K) e, L3 \3 `: I& N
16. Given the following variable declarations:
2 Z' p$ E4 [- C6 d* [3 a8 yBoolean b1 = new Boolean(true);7 L4 T/ O% b4 _8 z" s. @
Boolean b2 = new Boolean(true);0 P6 v9 O2 B$ q1 K
Which expression is a legal Java expression that returns true? - a5 c4 S2 M7 B. H* C
A. b1==b2! h3 N( j# f: B j
B. b1.equals(b2)2 M c4 l) |3 l4 Z- o$ z9 g8 [
C. b1&&b2" p+ C4 e/ m9 \
D. b1||b2
' [3 P5 H8 R8 s; [6 WE. b1&b2" n5 o2 z; t' _9 W) D S9 [! N
F. b1|b2 X0 [) d1 r( ?. T# `
17. Given:
2 L( z. r' ^% b( r6 c1 f5 f& i1. public class Employee {( H4 l' h. r9 q2 q1 G; V6 L2 L# ?! X
2. . s# c4 _3 ^: m; @
3. }
2 L4 v, q* D* {- E# I4. ( E+ T" i$ H- `4 W, J# B
5. class Manager extends Employee{
- x6 y) p% l# r! b- P! R: Z6. }
9 a) r0 m/ q1 y2 `. bWhat is the relationship between Employee and the Manager?
6 K, {7 e C6 @1 f# oA. has a; i+ C; q3 A" v j2 A' K* E( v
B. is a4 ?3 E- p" g: B$ `
C. both has a and is a
* d6 L& A8 p0 p% _8 P( h/ kD. neither has a nor is a
+ u4 A2 o# A, w4 C18. Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
7 H3 {. [4 G4 J% b$ e1 C1 X2 f2 ]A. BorderLayout* c& }% l1 K4 z; T, w
B. FlowLayout
& z3 O# d% R. dC. CardLayout
3 W- ?7 a4 ]" }- C3 {) P. w1 a MD. GridLayout
; b0 @! I; g: U6 _. \( L% s" h' _19. Which of the following AWT components can generate an ActionEvent?
& Q- _: {% s% u a0 r2 vA. java.awt.Button" X# _, u% ~$ B! Y
B. java.awt.Panel/ ?. H, X% y3 G. D+ P! C; O
C. java.awt.Canvas" h1 L1 M' { `% D6 r" f: _ {
D. java.awt.Scrollbar$ k0 q Z- E; Z* m' Y9 w; B
20. What kind of Stream is the System.out object?5 p2 U( B% Z z+ c
A. java.io.PrintStream' m; ]7 T0 o6 [/ z" }, f1 Z% D
B. java.io.TerminalStream
W0 Z! I' A& @. Z- fC. java.io.FileWriter
5 p( z/ l6 _6 m: b1 DD. java.io.FileWriter) v) U2 k; B* S! L3 L( b
21. Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选); j' p1 i( e* Z. l, F
A. java.awt.event.FocusEvent, r- f; h' ]* X# G3 E) b% \
B. java.awt.event.KeyEvent+ {1 ?( @9 u. @1 S' a! \( ~9 D
C. java.awt.event.ItemEvent6 M7 U. }- B/ A4 `3 D
D. java.awt.event.ActionEvent# l! Y( Y3 g/ }9 h- G$ H5 P
22. Which of the following methods are static methods of the Thread class?(双选)
1 o; f4 ]! \8 g0 hA. sleep(ling time)
) ~" [2 w3 Z* M# F) `& ?. ] |: I2 }B. yield()- A) \. H F8 P3 _
C. wait()' y1 m+ v. h1 V' t1 r7 ~
D. notify()$ e2 q2 N4 r/ f* t/ R
23. Which method do you have to define if you implement the Runnable interface?: Z Y" c9 |6 {, h
A. run()* i6 G Z7 { y$ g+ r
B. runnable()# P2 |" p- e% ?4 Y
C. start()3 ^: A- V4 n3 t& J! |3 X8 t
D. init(); ]% `9 q/ x& W, z3 H0 ]$ e
E. main()
: c: n! _! q. h, M* h3 l24. Given:1 H6 X' M. i4 j
1. class MyThread extends Thread {2 @- |0 t; n- U/ E" x
2. ' T; ^7 [) F+ y) E8 O! F/ n0 N1 v
3. public static void main(String [] args) {1 t2 C' Q5 L2 t- J* _
4. MyThread t = new MyThread();
+ S/ j4 K( S( @. _& g5. t.run();& n- @# ?8 l2 Q p0 y) i* ~
6. }) j* u+ D& Q5 @ @* ~" y
7. 5 f5 m) C& d0 s7 I" o
8. public void run() {
3 t4 D9 a$ I/ c9. for(int i=1 ; i<3 ; ++i) {" V' l* r3 u2 b) a0 f
10. System.out.print(i + "..");0 T. j4 ~. M7 Q0 v
11. }
! A' f4 C) D; s1 x& B0 z% R12. }0 k8 i! Y+ {0 H/ k# q$ p/ F l
13. }
9 b9 @; b% l( H* i' U( I" R3 uWhat is the result of this code?C. h8 c& ?( u5 j/ P# [4 ~3 O
A. This code will not compile due to line 4% \4 r$ j# W$ g" Z' [* ^6 ?
B. This code will not compile due to line 5
0 [' R- u# ^* D) w xC. 1..2..3 O0 _7 o. e, O. X! |0 o
D. 1..2..3..
: ~0 q; X0 O1 Z% I% A3 A+ D25. Given a local inner class defined inside a method code block, which of the following statements is correct?
( ~3 ?* H* ?' S% Z, L9 o$ IA. Any variables declared locally within the method can be accessed by the inner class7 f$ O& s9 V0 i% Y H M
B. Only static variables in the enclosing class can be accessed by the inner class
& @6 V* C: ~; a5 U; \: IC. Only local variables declared final can be accessed by the inner class+ ~( N+ |4 w. z3 G3 U% c
D. Only static variables declared locally can be accessed by the inner class.
) Y8 _/ N! \! b ]/ o' `
6 \- B! `8 v( z4 S" `4 K" Y' Z+ |. E- d9 o$ T
) M. ~8 f- x/ T2 a3 |8 o
26.public class SychTest{ - e4 A# w7 C5 U9 c7 ~
private int x; 2 `# p9 ]1 a& J0 T" g1 c
private int y; + X; M; Q2 T, y) V) p( I
public void setX(int i){ x=i;} 9 k5 l3 C. N; `/ ]
public void setY(int i){y=i;} ) F, U% E; s7 L+ L- c/ u1 u) s
public Synchronized void setXY(int i){
' r; m0 M: Z; |+ Z. s' `- X6 m- m" B setX(i); - J$ U2 p7 J4 Q" @" D
setY(i);
: e7 j0 O! S% A I& Z" s }
3 {* U' D" ^5 L1 p, d public Synchronized boolean check(){
) y0 A, S- B) M return x!=y; , |9 x- u7 \7 c3 K% ~
} 1 ~. s1 y( a3 v2 K
} 2 D) p/ V* |$ M: e
Under which conditions will check() return true when called from a different class? ; T0 n: x H1 ^9 [+ L6 T
A.check() can never return true.
e$ p/ \; Y( y3 r8 _8 E B.check() can return true when setXY is callled by multiple threads. * Y/ t. V& ], b: `0 d+ w9 ~
C.check() can return true when multiple threads call setX and setY separately.
9 `/ l% o' }! q4 A: e/ r" d9 [( y D.check() can only return true if SychTest is changed allow x and y to be set separately. }, {: f& `- X1 Z4 k/ C
' a' n. I, J5 d) Z8 @3 ^' O" {) p27. 1)public class X implements Runnable{ 1 {' m: \+ e, O( |0 n( W& E6 M
2)private int x;
1 N; l6 }" l" P% g2 B; `* A$ v 3)private int y; % I! J1 d( g# n5 X1 i3 K
4)public static void main(String[] args){ 1 [4 b. ]! l4 b6 m% ?5 m7 ?; b
5) X that =new X(); 5 o" M' T# E$ Y9 {
6) (new Thread(that)).start();
+ \. P) N% Q" [/ w1 @( a9 G4 ~8 J 7) (new Thread(that)).start();
! F3 x" \, D! J2 T. V% u } ; X2 y: T) ?+ R( D7 T& d# T
9) public synchronized void run(){ 4 D; w; W2 D5 e! }1 S m$ R' a
10) for(;;){
- t7 A( i# I/ N0 i! y 11) x++;
/ n, g8 i7 X, z 12) Y++;
2 @2 o0 {( l5 M4 I9 o 13) System.out.println("x="+x+",y="+y);
9 ` l& v' m2 s9 N/ E! n; w/ q 14) } 0 V% a& M3 o; [7 |$ J# B
15) } + e1 c M: B2 ?' k: [! ]% \# M
16) }
8 O7 L# c! u% E! [+ I( W what is the result? ) k% r' w0 x5 b2 {% o/ S
A.compile error at line 6
% i* P5 c2 `4 T+ ~9 O" h3 H B.the program prints pairs of values for x and y that are 6 C, f9 a8 n4 g3 Z3 P6 W
always the same on the same time . b) f: Z5 ]+ H' }
- X2 q& h6 E% C2 H% R9 o; v8 b8 q4 k: x28.class A implements Runnable{
9 `" k" n! @% t! A2 E int i; 1 ^: Z+ W0 ~% x4 `& p5 u6 \
public void run(){ : z- H3 A% p& D
try{
2 I2 G0 V, k% j1 \ Thread.sleep(5000); ; N6 B% A6 x5 D3 _. C4 X5 {3 j
i=10; " ~+ Q% u; c b* g6 u
}catch(InterruptException e){} # P8 X+ l: U- }6 y$ h8 j
} " g# `3 a e/ S
} 5 c4 [8 y2 b' `/ J
public static void main(String[] args){ ) M+ z x E, ~
try{ ; `1 o) y& g) ?( s5 |( N1 a0 m
A a=new A();
, W$ e9 T8 R/ F7 \5 m% {, i Thread t=new Thread(a);
3 |8 Z( k) b$ m: o: B9 y' x t.start();
/ a+ t& O4 k- R. k7 u 17) U4 a2 Z! W1 y3 T4 o2 l- Y) o3 X
int j=a.i;
5 B8 q' Y3 F7 O* Y& o& q 19)
$ V" {: T4 q& N2 X }catch(Exception e){} 9 \/ M) A' f5 [2 Z$ O
}
0 t/ \! g) O; v$ p! D } : y5 c& ?5 l2 _: u3 T; D: R8 ?
what be added at line line 17, ensure j=10 at line 19?
0 b" E1 j. N8 B$ K A. a.wait(); B. t.wait(); C. t.join(); D.t.yield(); " ]9 E1 {" B3 e+ }- n7 g
E.t.notify(); F. a.notify(); G.t.interrupt();
! Z7 s9 g! r3 j6 l9 N& a% o7 v29.1)public class X{
$ b; n! ~6 m' p0 @/ G/ N 2) public static void main(String[] args){
% j9 @( |# F" I+ Q 3) String foo="ABCDE"; 1 w5 c& h+ Z! ^
4) foo.substring(3);
+ S6 ~- F: h4 U, p$ m1 K8 D1 \, } 5) foo.concat("XYZ"); $ I9 O6 @% ~, v6 {+ s7 x/ l- q
6) }
w6 H, U+ C2 |9 A5 Y 7) } & C/ P4 n( X% r% b
what is the value of foo at line 6?
# |; A7 A4 @+ y- W3 B8 Q30. public class Test{
9 \) Q/ c$ w, c) ^ public static void main(String[] args){
. b5 S: V- f$ N7 _ StringBuffer a=new StringBuffer("A"); + l/ F: O* u& z! O9 q+ W
StringBuffer b=new StringBuffer("B"); ) Q5 X: S' |# d N
operate(a,b);
# u6 s I" b6 L$ V, D* k System.out.pintln(a+","+b);
( f5 S/ D# s2 X1 T" v: Y% U } " z$ \- C8 ?, j$ N1 K9 `3 w
public static void operate(StringBuffer x, StringBuffer y){
8 T" d9 @, ^2 {! j( p x.append(y);
7 a% b9 k7 [2 N5 S! E( o& U# j# ^ y=x;
' x$ m, V, \. X/ S } 3 U) O1 g) J) a8 a
}
. |0 \0 Q4 t- ]7 v7 B what is the output? |