Sample TextJava培训考题 t$ q: p8 Q8 ?9 u) @
1. 给出以下程序:
4 j, ]9 J* i9 _5 ], |! D1. public class Colors {: j0 O7 b$ {1 J# i: j
2. public static void main(String args[]) {$ ^, A/ W/ \+ i! T6 C
3. int n = 1;
T* D7 k& m7 {! a& p5 n2 ^4. System.out.println("The Color is " + args[n]);9 _; R! S9 h0 D
5. }+ Z/ \$ j( D1 Y9 t/ z
6. }! d, k ?' l* _" C- Z
假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”5 y, ~! q# i' M: R5 H) H
A. Colors red green blue yellow
, W0 j/ v0 ~. s' I. }B. java Colors blue green red yellow
; Z/ \7 x3 }2 s7 l0 W1 @! K& m% W; LC. java Colors green blue red yellow0 k9 k/ i. W1 z! k
D. java Colors.class blue green red yellow
7 y. i4 }/ q7 |. nE. java Colors.class green blue red yellow5 | x+ i6 ~6 a! V% {$ F
2. 读程序:
[& t& d; {# v& b1. public class Test{
/ ^$ h3 m- i7 `. p7 N) E2. public static void main(String args[]){- M8 J2 Y. G4 p+ C4 p
3. char c = '\u0009';
$ C# N) C2 {, p5 B, c2 r4. if( c == 0x0009L)$ t7 k( x3 `. n3 P' K+ J
5. System.out.println("Equal");( l l* }. Y0 c$ e" k- {
6. else System.out.println("Not Equal");% |9 l+ s7 F! o' f6 v3 D, v) n/ g9 Y
7. }
0 C* G# u( s5 x/ y o' V: i+ X( A8. }
( L2 {0 D3 i3 ?6 M/ v/ i# O: v# X; J当编译和运行该类时,将会发生什么:& O/ K, ]" Z/ n& d9 h! }7 x
A. 程序因为第4行将出现一个编译错误
" ~. E8 M7 R$ i9 u a. ?B. 程序因为第4行将出现一个运行错误
1 H+ a) t ~( zC. 程序因为第3行将出现一个编译错 i4 B5 ^/ U- t: A( ]6 }
D. 程序输出”Equal"
% K$ g' Q; K* |1 S4 r0 @' Z- p; FE. 程序输出"Not Equal”. X( k* v4 Z6 u+ U+ F
3. 读程序:- _& c& }7 C; ]9 A9 n
1. public class StrEq{
& n, g, K* C8 @" Q) d& \, X7 d2. private StrEq(){+ t* L# H" h1 P( }8 A. _5 z
3. String s = "Bob";' i& D& D( t; m8 z7 A( g$ R6 O4 H
4. String s2 = new String("Bob");
9 K2 G% ^! E, ] C; d5. if(s == s2){
3 X* R) ] P* V- M: k/ t6. System.out.println("Equal");! ?# d" a( e8 |9 S. g) y
7. }7 d6 d" M3 y. r9 l9 Y" ?
8. else{
! n4 }" ?. C' u" `9. System.out.println("Not equal");
0 t5 }0 y# l( z( E3 F; N. b# }8 n10. }
Z: M1 C! r2 i% l7 B11. }
4 B5 W: X! M- t& i12. public static void main(String args[]){
: I) o( k L1 M+ a9 c* Q13. StrEq s = new StrEq();
% R& ~, A$ q8 q- g$ G* c% |14. }
3 Y$ u/ U8 Z9 @3 H15. }
2 `1 i N" H1 j. A$ R; o% u' Q当编译和运行该类时,将会发生什么:) t# B/ M K/ j* F
A. 程序能够编译,并且输出“Equal”7 X' ^* j3 t; {2 n! ?8 b8 T
B. 程序能够编译,并且输出“Not equal”
: Q$ H4 t0 }% F2 ZC. 程序因为第2行导致一个运行时错误$ A4 N2 `+ l2 x, k2 z
D. 程序因为第2行导致一个编译错误
9 d3 E" C& }7 x+ E% W T4 z4. 以下那个赋值是非法的:* h+ v z/ U0 L* Q$ s5 g! a
A. long test = 012;
) D. M8 x1 p$ e' bB. float b = -412;
7 C& G, F. A& N8 v$ xC. int other = (int )true;
+ i. h& V2 K1 d% z1 _7 lD. double d = 0x12345678;7 j) ?9 n2 l, _
E. short s = 10;7 G- |7 ]7 g& Q, S& e% o" w6 a! b
5. 读程序:6 x0 Y9 y, w6 S+ k' s
1. class CompareString{
2 `4 S' P7 P1 m$ j2. public static void main(String[] args) {" V/ Q' K' o# e$ }5 H$ l% v
3. Integer x = new Integer(5);
7 g* j/ ?( S9 f+ ^) n4. Integer y = new Integer(5);& v6 d7 G9 ?- B& ?1 k1 J8 G5 P* m5 ^/ z
5. Integer z = x;
' T; V5 ]+ ~! j5 \7 N& u6. if ( ______ )! _, ~' L% e( w/ \8 P# ]
7. System.out.println("true");, {* z2 v. D- O
8. }
- W2 b7 q/ @9 O9 u& V9. }* S3 W1 e, P6 O. {5 @" Q) d
以下哪个选项填入第6行后,不能输出true:2 t5 s( g* t7 H0 \6 r
A. x==z
: }! g/ I% |' I5 c. {/ F" e9 fB. x==y5 q/ q7 x# b3 n7 |" v+ B) ~( c
C. y.equals(z)3 [7 g8 m+ U; n& p$ }" }: S! D
D. x.equals(y)1 ]& n' s: J8 d- {- x* r/ d- p. i
6. 读程序(双选):0 Y4 D) R* O! s6 _% ^5 H
1. public class Declare {
8 i; p* W6 } B; i2.
! y: c% g( O4 ` \* e. r3. public static void main(String [] args) {! i+ Z9 v* s1 a; J5 ?
4.8 y* [ ]% z0 k1 h: D
5. System.out.println("The variable is " + x);/ d9 Y4 M0 g' E+ c2 _6 D
6. }
/ A: i- Q' B2 t/ p7. }# o1 m2 U0 F. ^) _& d- s4 r
以下哪个选项中的代码可以使程序编译通过9 H5 _" B2 E9 A- }
A. 把“int x;”放在程序的第2行
0 G/ ]3 N: ]- }4 C, y/ O' CB. 把“int x;”放在程序的第4行
5 h3 _# x: q# s$ K2 TC. 把“int x=5;”放在程序的第2行
5 e8 p8 Y3 M4 M( R. A9 L8 z# yD. 把“int x=5;”放在程序的第4行 J" l6 f3 K* c" E5 o* F
E. 把“static int x;”放在程序的第2行
0 b5 j" t9 @" [, O5 _2 _/ ?" R
. _" H7 R7 Y0 ^2 w7 O% x- z* x6 }0 G# b, I' [8 ?3 Q( T+ G- s
1 u1 ]; R" ?% Q6 Q4 \
7. 读程序(双选):) c& C) S" f, E
1. public class Child extends Parent{
0 q2 M" |8 m* A I2. int a, b, c;+ W' \7 Y/ c/ z& ~" {$ J: ~
3. public Child(int x, int y) {
; X+ h3 f& g( ^7 R2 D( @4. a = x; b = y;1 T& B3 n$ [! o5 q0 ]
5. }
5 L) J2 D2 L; c6. public Child(int x) {
# e. v5 @1 Y1 d# U$ \. ]' U& ?7. super(x);8 _: s- a% U# j/ a9 Y% ]
8. }
8 ?/ G- S" K+ o# g9. }9 d* \# C j7 J! Q( b+ v0 R
为了能使该类编译通过,下面那个构建器必须出现在父类中:
5 l: y0 x' S/ I* ]$ j5 AA. public Parent(int m,int n)) N! x" j+ j. F4 g3 A6 k
B.public Parent(int m)
& A' ], Q& W. ~" a% v; XC.public Parent()/ V! W z$ T( c6 |& U! ~
D. public Parent(int m,int n, int o)
3 u$ G8 ^$ \/ N" {) W- Q8. 读程序:7 j! R- o$ n1 Q+ z* f; E' y
1. public class Derive extends Base{
9 a: f- x$ z: }8 C2. public static void main(String argv[]){/ l( v, T2 {/ u6 f3 Q8 v
3. Derive a = new Derive();
& I0 d, }/ ^, |4. a.method2();
& U# H5 }% z8 t+ H5. }
0 N7 J& z/ |. K. F4 K8 D. X6. public void method1(){" B$ n/ {6 F( x) n
7. System.out.println("method 1");
# H/ P6 G# @$ W8. }
, z& I8 X3 S/ {( i+ s0 Y4 n$ j9. public void method2(){# m" R9 F4 ?5 ^" }
10. method1(); ! c# U9 x8 d5 |, j5 I
11. }: H7 E, J; E6 u2 I* j, o
12. }
+ n8 N9 @' E+ j, h: K" s) y; a13. abstract class Base{
( r+ M; P0 s% d" Q14. abstract public void method1();4 b' T3 a# X0 ^8 V
15. public void method3(){
( y# Z$ ?2 r+ O- P" _& D* o16. System.out.println("method 3");' l4 r$ y h o4 ~
17. }" G# c p0 G" C" { O+ B
}: e+ y/ k5 M. t/ h
当编译和运行该类时,将出现什么:
, M. r# `& P" b% qA. 程序输出“method 1”7 ] E& i8 m% q7 W5 Y
B. 程序输出“method 3”/ @3 o, V, ]' S; {
C. 程序因为第15行而出现编译错误
9 o7 N' K( h3 F' |* n. S7 [D. 程序因为第15行而出现运行错误
; T# O5 D( X( g1 R' J5 Q9. 以下哪个接口的定义是合法的:, g3 Q3 _2 M7 \0 Q$ y5 m
A. public interface A {int a();}
; s$ z1 T& F, j, A, ]B. public interface B implements A {}( @1 r5 r3 I c4 F5 v
C. interface C {int a;}( \% |" W/ B8 T% o# M
D. private interface D {}; d+ L8 b( v/ V0 G5 G8 O
10. 读程序:
0 p% z" f4 z5 Y7 w3 L3 A1. //File SuperClass.java
* W0 ?! A2 ^: ^6 G. ? ]" j* i2. package MyPackage;
) @! |) ]9 y' n/ E+ V, r$ O3. class SuperClass{
( O# z6 w$ j- V' ^! |' z: @* W+ M4. void myMethod(){
+ X7 X' C9 \, G8 Y4 A5. System.out.println("SuperClass");
`& u3 K7 U: G |! g6. }, z" V. `* Q; u# L' y
7. }
2 q% g4 G# [( u6 X. O7 v4 n2 G8. //File SubClass.java+ u: z* D9 N0 c% l' J3 L
9. public class SubClass extends SuperClass{
) ?6 J; c* e8 k% Z, y; X10. public static void main(String[] args) {
, a' F$ g+ h0 t1 T' D+ o0 b- H11. myMethod();8 y" k; D1 M# v# r) [
12. }8 Y# p, U+ T0 X m
13. }+ X4 _) Y7 Z4 s# s, J
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
2 U# z4 V0 j4 m/ SA. 两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
9 g. ]* g4 p( s, O: f( EB. 两个类都回出现编译时错误' _! b, P( U6 Y
C. 两个类都可以编译通过,但SubClass会在运行时出现运行时错误
0 |8 o0 s+ B' T; V LD. SuperClass.java可以编译通过,但SunClass会出现一个编译错误% \8 a: w6 e$ ]+ M, X& p+ M
11. 读程序:
1 i! d( l0 _7 A3 `& w1. public class Test{, a& k% B) G! Y( T& s# j
2. public static void main(String args[]){
5 | u* o! K1 u) D8 T' R3. int[] i = new int[5];* d- ]2 r5 |7 r5 y/ G4 g* x4 i
4. System.out.println(i[5]);3 x2 X& d5 e% |1 j/ M
5. }
7 M0 p. H* G& m M6. }8 W3 s4 I% [4 W) Y& _+ T
当编译和运行该类时,会:
% _8 ~7 e& r5 J5 D# `8 fA. 出现编译时错误- x! L, S2 z: |6 j; f! C! P1 m
B. 出现运行时错误% ^ B# g z- m& |& S
C. 输出0' d! k) v0 W" q6 O# j* y: f* ?8 J
D. 输出null
, e" a Z6 m7 _7 y/ A( } r12. 以下哪个选项是正确的数组声明或初始化:
0 b2 u6 `1 `7 x+ pA. Array sizes = new Array(4);, ~1 b; r$ t; ]' T( r
B. double [] sizes = {1, 2, 3, 4};: \+ ]6 I: k- |+ I5 V
C. int [4] sizes;
4 w3 X- U9 O1 e* gD. long sizes [] = new [4] long;* C4 J. n5 `* ~' e& _1 v% s
13. 读程序:, ~$ f9 D" f0 h$ A7 e/ o O& Y% g
1. public class Initialize{& m! W- H) y; H9 b7 `$ ~
2. int x = 200;
. L% ]3 b( E5 h1 p1 ^8 v4 [3. static {: p- _ T7 H7 q0 y8 H' a" g
4. int x = 100;
6 z5 c7 |* E: a5. }
- ?" d# p* P' ^& M" I6. public static void main(String[] args){
( D \) u/ \9 m7. Initialize init = new Initialize();6 Z4 c) |) t) S' L
8. System.out.println(init.x);8 V% [/ U0 Z; Z
9. }
) ^1 k, \1 b4 @- G4 j# b; G& R10. }
, A$ c2 e% [" g/ p+ O当编译和运行该类时:* v5 F" o* s: w* g6 r
A. 程序因为第3行产生一个编译错误 R+ n* T, R$ L6 ~' h: X, U
B. 程序因为第4行产生一个运行时错误
" J; o7 S7 h5 CC. 程序输出100
3 [; p7 |0 S/ a8 G" R) ~, ]D. 程序输出200
4 | V+ A9 Z- }* C14. 读程序:
0 ]( o d5 w: `- m. ^$ n1. public int abcd( char x) {
+ @. U8 A) K/ N0 t2. if ( x <= 'M' ) {8 d, z& |8 k7 c) l) c/ t" |4 I* t
3. if ( x == 'D')
6 z, U; p/ g" T ?* e# w# f/ @4. return 2;' A/ e* c& o( O5 g6 M% N9 j
5. return 1;6 r) c% ^9 J) v2 k( {# o# f
6. }
) ~6 F. w* ^8 i7 j8 F# p7. else if( x == 'S') return 3;
5 @3 a7 y' [& h4 M& I. x6 {% \8. else if( x == 'U') return 4;
- C5 S: Y A: _! _# F) M$ I+ h' B" Y/ d9. return 0;
: ^( X) g( O2 @10. }
7 n" K' d$ _! }+ `& _, @* S0 d在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1* C1 w, L6 l0 K Z
A.‘X’6 ~- J/ k" `* S1 G. E
B. ‘A’
- _! x& @! b: V8 y6 qC.‘D’; u0 r) j5 u( e/ V6 I/ `$ p$ r
D.‘Z’% b, w# R* }9 H0 U1 @( s$ @9 U
15. 读程序:/ X; D' u/ _: I1 _9 p1 c: X5 {
1. class TryTest {+ G$ Q/ @* h! e) @' N
2. public static void main(String[] args) {. e3 l* F# L0 a- J% m @
3. try{; ?" p w0 _- e; `0 k* R7 }
4. System.exit(0);- z2 Y' X7 m/ W9 r) {7 h- F
5. }
; I6 D, m+ Q6 [( }; ?6. finally {
8 ]1 q. S8 m' x7. System.out.println("Finally");0 u g0 l3 W* u/ B
8. }
. r- B& M: Q$ b4 g9. }
b1 u+ J: r7 C, u: I7 S10. }
0 }9 c6 d; e& _当编译和运行该类时,将:% q# M8 _" x) a7 |! C3 A6 C$ I' ?% ~
A.程序因为第4行出现编译错误1 [ o, j5 e% D. W7 N% d
B.程序因为第4行出现运行时错误
- ]) ]! c! C8 w7 d: A/ f0 T3 {C.程序因为第6行出现编译错误
, X1 K) a/ z3 MD.程序因为第6行出现运行时错误+ p0 Q- j: t4 j
E.程序输出“Finally”' O- n" J7 B; ~. A
F.程序可以运行,但什么也不打印2 u) F E7 c8 {
. H7 _ T9 }. S. v0 Z! L16. Given the following variable declarations: V; e4 b0 C) B4 k
Boolean b1 = new Boolean(true);
. y: s2 }5 X H+ o5 x, W3 @, nBoolean b2 = new Boolean(true);
, ?# h% E* U. z" eWhich expression is a legal Java expression that returns true?
. _$ O+ |' O3 F6 M- P' GA. b1==b25 N- D7 Q4 a! K8 E/ y( ]
B. b1.equals(b2)' F3 i3 Y$ R! t% b( r# H: Y l
C. b1&&b2
; G: r6 T# `' k1 v" G9 yD. b1||b21 ?7 H% U+ c% [
E. b1&b2$ {1 ], l+ O0 c2 N2 U8 M- X
F. b1|b26 v' y; M- }" v7 t
17. Given:
2 u1 O3 `5 M2 d U1. public class Employee {5 G! z5 K/ |7 \ A% d; Q
2.
: ^" z4 ]* G! J4 g4 a9 G5 f3. }
8 X& F/ W5 i5 W) d4.
' n2 T9 D* i2 H4 i7 n5. class Manager extends Employee{, ~, U. e7 ?2 n4 {( A$ w- |
6. }
3 i. O- P% b8 lWhat is the relationship between Employee and the Manager?
2 y# @5 B+ @4 L5 r aA. has a
* Z$ X2 ]) Y8 E" i% d8 BB. is a! k" ^$ @4 q" P Y
C. both has a and is a4 e/ I$ V0 l0 q% L& w
D. neither has a nor is a6 F) f1 D1 v1 e( d
18. Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
0 O7 |0 ~9 L9 M E. rA. BorderLayout1 U2 q" S C5 Q- k& e: N! t" h0 F
B. FlowLayout
T# @4 E3 O9 t# r1 gC. CardLayout# y* a! p2 J) i
D. GridLayout3 e+ o+ J' T$ x7 W2 V
19. Which of the following AWT components can generate an ActionEvent?
3 ]9 p: S1 L" ^( w( XA. java.awt.Button
4 Z& C7 a5 t/ H9 m$ SB. java.awt.Panel
/ c; R; m7 K) \) H5 T+ T5 A2 Y2 U4 PC. java.awt.Canvas
( X6 I1 \8 a2 S' p* t' e/ Y6 ]D. java.awt.Scrollbar( T; H) b6 w7 a: J0 Y
20. What kind of Stream is the System.out object? G& t) @1 G6 q7 L
A. java.io.PrintStream4 v( G; Y1 D( K' b" B
B. java.io.TerminalStream; z* E3 Y7 f* N: x# }' _. n& ~
C. java.io.FileWriter& p4 u1 o. C7 y7 W$ Y
D. java.io.FileWriter+ K! L6 n2 G4 Q* E* @
21. Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)
; i: Y& x w* wA. java.awt.event.FocusEvent. ?# c- g. D1 [. i( O7 P
B. java.awt.event.KeyEvent
1 j# b/ k7 H7 N, Y% r$ yC. java.awt.event.ItemEvent
6 F5 [7 v9 f4 kD. java.awt.event.ActionEvent0 _$ @6 x! m7 p
22. Which of the following methods are static methods of the Thread class?(双选)
% C8 N2 _9 h+ I" MA. sleep(ling time)- ]7 D ]$ d+ N
B. yield()$ e3 o7 [+ p9 }4 c! I' L
C. wait()
C9 G, V* T+ w5 ]% w7 @D. notify()
3 |' E) {, Z* S' p7 p% O23. Which method do you have to define if you implement the Runnable interface?
# X& H% |, ~" T5 v3 J) DA. run()
: x! z z/ E$ x7 z3 C( i) NB. runnable()$ P* C+ r! f' c9 U
C. start()
; i; w1 E$ ], e2 pD. init()
4 q$ P1 M8 r0 u- SE. main(). S: X! q e6 I/ [: N) r* Y4 S
24. Given:$ h6 E9 m! M) C
1. class MyThread extends Thread {
1 g' D/ l( p7 D2.
7 P. V! D! [. l3 o+ o1 ^! P+ {3. public static void main(String [] args) {
6 _* C) w3 X7 g( `, @8 T4. MyThread t = new MyThread();6 p# F7 B$ i& T4 S
5. t.run();- e$ j; W& I2 m$ w! O$ x6 u) H- R K
6. }
, B; R/ r1 T1 l+ J8 ^) I7.
& C2 m7 ]# [7 Y* G+ a8. public void run() {
& K4 U$ }2 y+ G& k9. for(int i=1 ; i<3 ; ++i) {3 u, ^5 V' r3 n# O# v
10. System.out.print(i + "..");: c V. e# i7 [ U' W7 G! h
11. }$ f3 I7 o! Z. N; B
12. }
, M! o/ o9 C9 m5 S& \13. }9 `/ w N; n8 c# u
What is the result of this code?C
& S, b; ~" S2 K8 i. WA. This code will not compile due to line 4
: m. U$ m: Q8 JB. This code will not compile due to line 5
' m( T8 B" N. j+ L9 Y' R4 `5 b3 YC. 1..2..
3 o; M8 t. J9 p o$ @D. 1..2..3..
8 Z/ ?8 K3 M9 d5 v4 v5 [# r$ Y25. Given a local inner class defined inside a method code block, which of the following statements is correct?
7 q8 V1 M. `; ?% @" A, q7 }A. Any variables declared locally within the method can be accessed by the inner class
1 w' t4 p6 j* B, t( \B. Only static variables in the enclosing class can be accessed by the inner class
( F7 p$ G' j+ x/ q2 q* [7 Q: pC. Only local variables declared final can be accessed by the inner class2 x( |) l. x% O& v
D. Only static variables declared locally can be accessed by the inner class.
2 y' t3 \, `0 G* [2 O) V9 s
* r! Z+ }/ _; i: h; Y7 l9 U
/ [" F9 z1 l9 N+ n3 o
- S5 c9 E: V# h6 ~2 N5 H. W26.public class SychTest{
0 O; Q+ b$ {. q; c8 R) W+ }7 B' h1 F private int x;
7 f5 h7 q7 f7 J2 l9 P private int y;
7 ~; u; S8 u! }! a! W. v public void setX(int i){ x=i;}
d8 x& [, _* K D( R0 m0 J public void setY(int i){y=i;}
' G$ S% I* X& q- \) P9 V. k public Synchronized void setXY(int i){
1 b; u& y$ c A& D% E setX(i);
- X3 }* I9 A! Z" w4 [' q setY(i); % f5 ^$ C2 e8 S9 s, n
} % p; t( @, G r& E& Y% h$ h" _
public Synchronized boolean check(){ & \) Y- ]; D; q1 [% {- N. v) _ n
return x!=y; 9 h7 _7 B7 c. ?" X
}
7 _3 Q: @6 s: o }
0 f. ^ |' H$ W8 h$ h$ l3 |0 i U Under which conditions will check() return true when called from a different class?
) e w5 _( @0 S A.check() can never return true.
, D/ k8 ~7 \! z3 e B.check() can return true when setXY is callled by multiple threads.
( h6 R6 a, M/ s# b/ g# w8 Y' v C.check() can return true when multiple threads call setX and setY separately.
1 \6 H6 x. E& l0 a; z D.check() can only return true if SychTest is changed allow x and y to be set separately. % d8 X, [ X7 y
4 n# n+ t: p' f- M27. 1)public class X implements Runnable{
1 D7 {: t7 [2 H4 Y( L& V 2)private int x;
3 v. b4 }" ?+ u 3)private int y; 9 p2 P$ q: G$ ^! K# }8 Q
4)public static void main(String[] args){ 9 U2 [8 o/ _' H2 l6 g
5) X that =new X(); 9 \+ Z' w5 u2 |# C# |. A
6) (new Thread(that)).start();
0 W# o# p$ C3 c 7) (new Thread(that)).start();
8 y2 C$ i$ W) f2 Q9 [4 d }
) M- v9 j) T$ Y8 K y: Z5 r 9) public synchronized void run(){
# k! T6 d; O# i! x, M5 U# V 10) for(;;){ , {$ Z6 a6 D0 b
11) x++;
0 j0 s6 P% w/ L3 R+ q 12) Y++; U: q3 M- x1 k2 v/ S1 T# o
13) System.out.println("x="+x+",y="+y); ( @& o( o6 f2 a8 P
14) }
9 l0 x& P- W% Y. \, ]' g 15) } 4 R. O# i( u9 E8 E) y
16) } 2 W! V* z% l; V' x- X* [
what is the result?
5 I/ ~. W. P, _% u A.compile error at line 6
9 N$ n- V' [" u% ^3 d3 ~+ h9 x- H B.the program prints pairs of values for x and y that are
7 L4 G6 `4 g& i# Z always the same on the same time
$ A1 H! Y0 ~% s3 B5 t+ y! S5 V: P0 U l& S( `- P
28.class A implements Runnable{ , G7 X5 s3 m& O8 S9 ~
int i;
9 K9 C' v" L! {6 B. _+ R2 b public void run(){
* W9 T( m) i4 x. i! u( T5 ^; z' ?4 k try{ - d. m6 {4 g) Q @0 d' f* S
Thread.sleep(5000);
7 z- x2 p/ d: D: B' e4 y" U1 r i=10;
1 \4 H! q/ l1 e }catch(InterruptException e){} ( u2 {% W" V! A s* w' S
}
2 R- ]2 M+ @: r, S+ p7 L% ]$ J9 W7 L } + T: c/ ^) t0 u7 @* D$ c) J: `4 Y
public static void main(String[] args){ 4 W% g! P9 j4 x& B+ ^+ P5 g( T# V
try{
9 _8 w ?8 _) l5 H A a=new A();
! B/ O' d$ G2 c# g+ l+ s Thread t=new Thread(a); 3 F& K; w$ I7 J9 ]
t.start(); $ J n! d8 R9 q# m1 |
17) : M6 }; j! a4 e; @! x
int j=a.i;
" K; ], c. |" O# ?- Q- B2 B 19) 1 [4 S3 U. U3 h1 W8 V; L0 @3 r
}catch(Exception e){}
- W8 W8 J/ \, I" ^$ X$ Y5 L } ( a% ?* ?. j2 w3 p8 I
} ) V; d/ G. T1 u0 k( a
what be added at line line 17, ensure j=10 at line 19?
; s0 ]# V3 y$ \: S: S3 W A. a.wait(); B. t.wait(); C. t.join(); D.t.yield();
. [9 n9 a6 r9 ?7 o, M" k E.t.notify(); F. a.notify(); G.t.interrupt();
8 y% n6 c' P+ q! J6 S4 @29.1)public class X{ / G& I l5 s# x1 N1 J# l, v& P
2) public static void main(String[] args){
; @6 j9 S8 ^$ S' N/ H) y, s8 b1 \( ? 3) String foo="ABCDE";
2 k% I( D' _0 v9 O 4) foo.substring(3); , f U( j5 s) q7 j
5) foo.concat("XYZ"); 1 o# _4 |" S$ b1 J2 \
6) }
i! |8 O) O3 c0 @$ S1 Z Y, t 7) } 3 x e" o. i9 a q# e7 `
what is the value of foo at line 6? 6 j9 P! G T- J/ ?, R
30. public class Test{ ) J3 [3 v3 @6 m! f% \! Z
public static void main(String[] args){
, f+ _8 T5 ~6 h5 a& R# j8 g StringBuffer a=new StringBuffer("A"); " _3 j) X5 { ~" m
StringBuffer b=new StringBuffer("B");
9 z% N5 i# f) X& q' s! \+ q' y5 z operate(a,b);
# A7 t+ S5 v* g# Z+ @! f System.out.pintln(a+","+b);
/ j, N) [" ^; w8 E( U% o } 0 U4 M1 @: q% i* p4 |% G; P3 I
public static void operate(StringBuffer x, StringBuffer y){ d/ I! N( P9 D( c3 ~
x.append(y); ) B v" d3 M7 l8 Z
y=x; ( U3 _; }* b+ b2 V2 _
}
0 U; G/ d* a! ~1 U }
# C8 M; L a# Y what is the output? |