Sample TextJava培训考题3 C- q1 R& P9 c2 a
1. 给出以下程序:
! i$ D' ?" y- t1 k, {: |1. public class Colors {/ [9 ^2 S& B$ b; Z3 A
2. public static void main(String args[]) {
7 W% |( ? H* `' R1 ]3. int n = 1;+ L% X4 T9 r4 A0 _- e) W- |
4. System.out.println("The Color is " + args[n]);
. ^; t3 m9 T1 {9 ^) `5. }! l5 y/ A2 _. Z+ Z' T
6. }9 W2 t6 F$ a2 R, l2 R
假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”0 T1 Y7 V" e+ |$ @
A. Colors red green blue yellow$ e8 H8 `. Z6 p/ Z4 b
B. java Colors blue green red yellow
- v; g2 E" x m- t" UC. java Colors green blue red yellow( l0 c ]" U( A, P6 B) ^
D. java Colors.class blue green red yellow* h0 G* o9 ^) U: P! n a- I
E. java Colors.class green blue red yellow
/ ~1 Q# ]+ v Y2. 读程序:* x3 c% f0 B9 R, o, O
1. public class Test{, {9 ?- H7 f/ e
2. public static void main(String args[]){
3 R1 y2 v5 q& _3. char c = '\u0009';2 ]5 a# _5 N" i) |
4. if( c == 0x0009L)
% ^' @7 D4 ^9 ]- j5. System.out.println("Equal");
- {: \1 h2 v. w6. else System.out.println("Not Equal");
" D+ d5 Q7 X4 \/ M/ U/ N( b) d; Z4 C7. }
$ ^# k" t+ u+ R6 Y; M8. }$ ^$ W/ A3 X4 q% C7 U" H
当编译和运行该类时,将会发生什么:0 f2 K$ h" P) r, J1 x
A. 程序因为第4行将出现一个编译错误
7 U/ N3 D [) X+ I% j' z( b1 b1 o, gB. 程序因为第4行将出现一个运行错误
2 D) N7 r+ [- W) r& nC. 程序因为第3行将出现一个编译错1 ~3 ^* I- A5 K7 g' K, r U
D. 程序输出”Equal"
2 P! R5 {* i# q; Y+ UE. 程序输出"Not Equal”$ j/ i X4 v' N
3. 读程序:
4 ]5 m4 `2 f! J8 n% n( K* j' F$ O4 E1. public class StrEq{
D t4 p# b" T. F; I! u2. private StrEq(){
0 w* O7 e* u: p. l- ]& `3. String s = "Bob";* o; q. ^! e( M: u: l( B
4. String s2 = new String("Bob");* E8 f( z" K, }& ~
5. if(s == s2){' R9 b2 n3 z A5 y
6. System.out.println("Equal");5 D3 B. e. X4 Q
7. }
& }: n, Y2 m4 W& m. |7 G7 Q8. else{6 y7 Q" ^3 H6 T! l' `. m' A4 i
9. System.out.println("Not equal");- S! w6 O; [ F" x6 E
10. }
$ O& N+ c4 k7 w" D11. }9 f# m6 Z T# m6 ?
12. public static void main(String args[]){- Z4 E" n% z! M8 _" S9 B
13. StrEq s = new StrEq();. d, D7 _. q5 f2 x& r" O9 a
14. }
; Q+ o* |! l7 m! f; U1 B; ?15. }) H7 o/ |. |( |/ I1 G! z2 T
当编译和运行该类时,将会发生什么:/ z' E. j7 N/ V
A. 程序能够编译,并且输出“Equal”
( k: |3 [% R- }6 I3 eB. 程序能够编译,并且输出“Not equal”% E2 J3 F, P' Q& c
C. 程序因为第2行导致一个运行时错误
/ J: ^, v) v( U' ND. 程序因为第2行导致一个编译错误
! T( R' ?/ E5 n( D" m7 c4. 以下那个赋值是非法的:
6 t! i% t+ g+ f; L0 e, N) ]A. long test = 012;
' n, J4 |4 N$ l7 v" U$ n* r! K D, xB. float b = -412;
9 S5 m% w' T, @" QC. int other = (int )true;
) T3 V9 o$ t/ y- L+ `5 G% `& FD. double d = 0x12345678;9 }* \6 `( b; |5 |
E. short s = 10;; n; y6 b# Q5 d. d$ I! S/ J
5. 读程序:
6 U* @) X, U6 p: E4 G5 D1. class CompareString{; W* ^8 K M, E
2. public static void main(String[] args) {
2 y; C! o4 N2 p9 s8 O4 \3. Integer x = new Integer(5);: b t V K# A1 k; S' k
4. Integer y = new Integer(5);
2 A, s- r% }9 v! y) }2 f5. Integer z = x; _/ e+ c/ U5 P5 Q9 F
6. if ( ______ )
' }- Z. z1 x; |. k7. System.out.println("true");
: _, v2 F- s4 I G8. }
4 u% ^, |+ i8 L9. }& y. t3 f( O. O$ W# \
以下哪个选项填入第6行后,不能输出true:7 t' Y J4 a; u" u' |6 `2 X
A. x==z( _& t! i3 {! P9 m1 K ^" a
B. x==y/ E) Y+ }5 m7 E$ b7 c0 A8 Y7 M U
C. y.equals(z). r3 y& ^" N! y- Z
D. x.equals(y)9 a* h6 m, A2 S H$ ?8 `# M. A
6. 读程序(双选):( f1 z. {# X; U8 ~ l% b; a$ V
1. public class Declare {0 |! R9 s) W2 A0 @
2. ?; _8 ^2 f6 x- ]
3. public static void main(String [] args) {& l. B- ~/ y6 F. C7 o T7 H
4.* H' `' g3 b) k) o
5. System.out.println("The variable is " + x);
. Z6 U$ H2 j3 A8 T: L5 j, e) A" f( S6. }
7 U. u( y( V3 d4 x0 G7. }$ N G! R9 }9 }/ p* V! \
以下哪个选项中的代码可以使程序编译通过; M* |3 t1 V- m. j
A. 把“int x;”放在程序的第2行
2 p; @7 r" m3 y: n! s$ B: @B. 把“int x;”放在程序的第4行8 X( D5 F- W6 M; S
C. 把“int x=5;”放在程序的第2行
5 @% |+ c2 l* Y( ]; BD. 把“int x=5;”放在程序的第4行
* Y4 v0 T4 B! {1 n" |. s4 R s, M; n; SE. 把“static int x;”放在程序的第2行; L ~; I) g) r, H+ {5 F: ~
' [9 ]- [' z: f7 o/ x$ ?1 \) K# A# C0 ?5 F4 I( S. l
) x: b7 D; f3 A5 z7. 读程序(双选):
7 A4 I0 N" Q: g- O1. public class Child extends Parent{8 i; h Y9 F- @1 o/ u
2. int a, b, c;( P# s s& B0 x
3. public Child(int x, int y) {6 w4 {% g" |4 {4 A
4. a = x; b = y;% N+ |* O3 R1 s
5. }
* b0 h+ {9 @1 f9 @4 t1 t& A6. public Child(int x) {5 r. f: M1 D& \* _! Z1 [1 V7 z
7. super(x);
3 x7 m- Q( d" l5 \! Z" w ~8. }% \. N: E7 l3 S! m- M- J
9. }& _4 {$ x6 ? K" f9 r# ]2 o
为了能使该类编译通过,下面那个构建器必须出现在父类中:! e6 J$ \1 r- k& u" _
A. public Parent(int m,int n)
) ?, L4 X. n+ S- `3 a. IB.public Parent(int m)* Z9 Y2 w) k J
C.public Parent() d% N. A' d0 ?' M$ z3 \" R
D. public Parent(int m,int n, int o)
# R, }5 l: j1 i7 }' ~+ G" z1 Z* u' d8. 读程序:, }7 w$ X, U" V& B$ b# P
1. public class Derive extends Base{
, d5 s0 t* Y% t3 p2. public static void main(String argv[]){
" k8 k0 Z& p4 h8 L z V3. Derive a = new Derive(); `" q. B U% z; V8 {' p5 H
4. a.method2();8 V1 d! r) Q8 v0 n. c
5. }( }7 M- F9 d" C. A+ q4 h( Z0 h5 B
6. public void method1(){9 Q/ H. _5 i. T# l* _8 a
7. System.out.println("method 1"); i0 G2 b$ y+ ]& f! a
8. }
0 o0 A2 e# i9 a2 V2 n/ J9. public void method2(){( ?. n/ F* B1 ^* {- `. o" _3 X+ K
10. method1();
" F4 z1 J3 f* S3 d# F11. }) p) T9 |7 F/ i" v5 Q* V
12. }
9 b$ O- p5 K* g& L13. abstract class Base{
+ ]. N$ i' _! t, K2 e1 X( f6 c' O p0 z14. abstract public void method1();
* G0 A5 R6 Y" J1 K: t5 J; O2 t& \15. public void method3(){: m7 Q0 a1 u) b. c6 ?" ^- ]8 z
16. System.out.println("method 3");
1 j5 @5 m7 Q$ a17. }
/ h8 b4 g& j0 B) w}' s( j% u" h7 G7 z3 q
当编译和运行该类时,将出现什么:, D) I& [4 n% |4 i
A. 程序输出“method 1”
% p/ T. O$ p& u( t6 @B. 程序输出“method 3”
3 c$ v% [: b" ?6 ~C. 程序因为第15行而出现编译错误
/ k, ?: h1 O8 A+ WD. 程序因为第15行而出现运行错误
. E- W! D9 [7 u( c" M9. 以下哪个接口的定义是合法的:& }8 o$ x* F2 ^) E) B
A. public interface A {int a();}# E/ b# X8 c$ t5 u; z& T& L
B. public interface B implements A {}
. ]) W4 i0 I5 u+ a5 m3 I7 u0 MC. interface C {int a;}
* B$ {& s; ^; n& VD. private interface D {}( `, b/ b6 ?) V2 T3 {1 K* h
10. 读程序:
/ \. N7 g5 j8 y9 i1 z2 F1. //File SuperClass.java7 z7 v+ z V- u1 P7 r+ `/ ?
2. package MyPackage;' m% T) ^* l% l& e" N! e
3. class SuperClass{
: {: w) W& u+ h. O( W* I; b4. void myMethod(){
. F, X2 J! i$ F5 Q1 O6 a5. System.out.println("SuperClass");9 q' v6 V M: J9 {. M9 Y0 h* @
6. }4 E: `$ V0 L# O+ a* `
7. }$ L; G- ?" H1 V9 ^( _: y
8. //File SubClass.java
1 M5 Z1 J6 l- H/ n/ {9. public class SubClass extends SuperClass{
# W. Z/ I& O2 d% T0 ~8 |10. public static void main(String[] args) {
# f9 N# [) L6 w7 n& g. Y) |11. myMethod();- X+ e2 x; i6 `6 w
12. }5 t ? O) T( p; b' [
13. }
+ K! f9 `) U1 P' O( A; C当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:
9 h1 ]. M! B; a9 b' FA. 两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
! g1 m/ k2 L0 |0 |5 V; w% wB. 两个类都回出现编译时错误; m/ h& Q' ]: I5 ^
C. 两个类都可以编译通过,但SubClass会在运行时出现运行时错误
6 l/ C5 L6 c5 @; k* b, q8 wD. SuperClass.java可以编译通过,但SunClass会出现一个编译错误
& u8 y) G' s& v' V" m2 s: S11. 读程序:
( m, M9 t1 }; {4 s' t! P* R, `& e/ Z1. public class Test{9 t2 F/ y2 N; o2 t4 ]
2. public static void main(String args[]){% Q2 g1 c9 @1 H/ _- v
3. int[] i = new int[5];9 {; F; z8 ]0 P/ |. ?& g% P
4. System.out.println(i[5]);1 f' ?, M W ?4 f" S
5. }- V' k0 r/ m1 b
6. }& Y. E( b6 f8 \% S7 \% i6 H. r7 C
当编译和运行该类时,会:7 s& W* R5 ~& m( R2 L' I& H
A. 出现编译时错误
- W, \: w! B1 NB. 出现运行时错误
2 F& ^5 k+ f( S- R7 Z1 o! |) ~C. 输出0
6 ~" }' a q6 D- t2 x. J- ?! U/ s' OD. 输出null3 S$ z' @! i: @) `: p% e
12. 以下哪个选项是正确的数组声明或初始化: s* g: C' H: r: P4 G2 m7 `# v
A. Array sizes = new Array(4);; T+ t; J. W* }* E! p6 D
B. double [] sizes = {1, 2, 3, 4};, j7 x% X% Y' |% ^7 S# j
C. int [4] sizes;1 I* G5 @) d2 F' f' K
D. long sizes [] = new [4] long;/ Y+ E) s, V1 S
13. 读程序:
3 o; s$ @) ` H0 u% Q1. public class Initialize{
) B+ u8 M/ x p) ?( K" [( A$ h8 i2. int x = 200;
% I' G) D e0 m5 N* ^. V3. static {
& K, p2 B5 y4 c0 P5 D0 M4. int x = 100;/ @6 |) Q; W' C9 y# m, U
5. }
7 w' J# c$ K. k/ G# g* Y6. public static void main(String[] args){
1 p `: ?3 o4 l, b7. Initialize init = new Initialize();& ? ^- d" l6 I* t; k) ^
8. System.out.println(init.x);- m4 ~8 D+ I( r* i' G
9. }
6 \& U& J1 H' v0 D; x" X10. }
+ @5 k- w3 Z, z. U$ u7 g当编译和运行该类时:
' L+ L" V: o% Q1 b8 v- L$ L6 f- _A. 程序因为第3行产生一个编译错误
5 E; N& T; A4 f: \( W6 SB. 程序因为第4行产生一个运行时错误
$ S" h6 y( y/ gC. 程序输出100
3 ^/ K/ t( _- ~/ {3 `; k# rD. 程序输出200& k' l- g4 q9 \4 @; K" u
14. 读程序:1 d( `" W" }: s! z' r( ~
1. public int abcd( char x) {; b O8 ^1 r4 _: L9 d
2. if ( x <= 'M' ) {
& a3 K. p8 ~! O0 e% K, j/ G+ ~3. if ( x == 'D') * u1 p# k0 a9 z* C; e' F9 Z1 N
4. return 2;
0 u/ B# g% X7 O2 M5. return 1;- C) D h5 @0 K; W( c
6. }* a% l; e7 w# T
7. else if( x == 'S') return 3;# L8 o$ Q. }' I, ~6 q
8. else if( x == 'U') return 4;
) p1 S6 r! x5 U6 ^& o9 p; {9. return 0;
7 k) r" A/ }- V8 \5 z" ?( M: H10. }6 L3 S& L& d$ e2 O! g9 \3 x4 P' ~
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
+ S* C) P! s. ~A.‘X’
/ m$ t* k) c) `$ a1 }B. ‘A’
6 q! E7 J6 A& q$ @. q* t p' VC.‘D’
3 ^3 N9 j4 I) s/ T# G; L3 ED.‘Z’
6 q% B: C1 r" L2 B" P4 F15. 读程序:
7 a: Q+ U) z9 k/ C& d! G% {$ H( {1 `1. class TryTest {" |' I; M$ ^. d. p
2. public static void main(String[] args) {
) n, _9 ?6 Q# p4 d0 s' `3. try{7 j3 }% D( T. X# e" F6 d9 i$ u
4. System.exit(0); [ _5 i' t! T1 q) w
5. }
7 s7 `4 b2 Q' s1 e& ~0 i' @6. finally {
6 z; b6 x, q+ R w; U0 t# M7. System.out.println("Finally");
0 N8 |+ K5 b. h6 M5 ^" | D8. }; t; K* l8 p' k2 I
9. } c1 V" o4 T+ R0 A* _) u1 f) O% w
10. }
, H5 J" X% y% s当编译和运行该类时,将:
6 @# y, P8 i/ V7 I, _A.程序因为第4行出现编译错误
4 Y6 ` z" a( ?0 l: e& O0 h# Q: wB.程序因为第4行出现运行时错误
' A) U: X G2 \( \8 Z. Y1 AC.程序因为第6行出现编译错误. I' I/ _; y& @* F3 B( Z
D.程序因为第6行出现运行时错误( j" x$ P: Y- Y8 k
E.程序输出“Finally”
) q0 X+ \: S* }F.程序可以运行,但什么也不打印
; }8 ]# v; i( B- y. Q( m) m2 k& U+ Q; n; E) l* V' F
16. Given the following variable declarations:" E I4 r* }* a
Boolean b1 = new Boolean(true);7 g W+ T( A1 c! l9 Y- s# \( h
Boolean b2 = new Boolean(true);
6 }9 U% U8 J) m2 v/ J5 PWhich expression is a legal Java expression that returns true?
# d( `" y4 Y. u9 V& wA. b1==b20 W5 f0 j. @# w" B
B. b1.equals(b2)
0 U' h" F& A6 Q8 cC. b1&&b21 I( G1 a$ P6 p/ `6 l
D. b1||b28 P5 `5 x' G* W: K5 x- T3 O% S
E. b1&b2
6 {! @8 K+ s; Y: @; ?F. b1|b2- K5 R/ e" Q4 |" R8 C) M
17. Given: 7 y: v2 f. r+ [3 O# h4 q+ p6 S
1. public class Employee {
1 k- j/ @* q/ U3 z- o8 J4 j2.
4 n& m' _, g& m3 k R; o3. }
7 q% U: V& i, A* E1 e/ c% j0 |4. ) f/ ^! x8 W! Z! y
5. class Manager extends Employee{
) C: W1 p4 W' [ n! T- R4 J6. }# v% |) \2 v2 O8 Z Y4 F! z
What is the relationship between Employee and the Manager?6 C) F! Q- a }6 d9 f
A. has a7 d$ S/ \( {# ?* e' Z9 ]$ q- _
B. is a
, O' n. z& X# s8 HC. both has a and is a
, e* g2 O' U+ H( b* {6 S, qD. neither has a nor is a) T" e! b! ]& I, a% V2 j# q
18. Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
: ~7 i. c3 p# ?7 ZA. BorderLayout
- P0 [$ S+ g2 V# w5 M) lB. FlowLayout
\, G: `4 l: V: IC. CardLayout
% t- B; @/ q7 v1 MD. GridLayout
; p, M3 ?) V5 D: l19. Which of the following AWT components can generate an ActionEvent?
2 Z( i, W1 F0 V$ X C$ M. ?A. java.awt.Button
% e W5 F0 K1 y: k0 k u2 G+ bB. java.awt.Panel
0 t" ~, ^+ b- G0 u i4 SC. java.awt.Canvas4 K3 p+ c$ F- c6 S/ X/ Y S" G
D. java.awt.Scrollbar, L% K( z$ d- _# h" L0 Q0 ^/ T2 X
20. What kind of Stream is the System.out object?$ u& M4 Y( P& A2 I4 j% e3 ~
A. java.io.PrintStream1 }- A6 a4 a' I$ l
B. java.io.TerminalStream
2 ^2 G# l8 n2 R5 KC. java.io.FileWriter
% R! X. q( M: \& qD. java.io.FileWriter
/ z; |3 f: l: Q A4 n21. Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)/ ]& [& o/ g3 ~
A. java.awt.event.FocusEvent
* ]7 G e: d2 _5 n8 K) SB. java.awt.event.KeyEvent
: r( a% R: m, ?/ i) k7 S1 P5 DC. java.awt.event.ItemEvent
: H% `6 Q- U9 ?3 i% tD. java.awt.event.ActionEvent
: E7 V4 F9 A( U3 K" @; {" m$ ~22. Which of the following methods are static methods of the Thread class?(双选)
2 F0 z# |, [7 [7 \1 J7 _) WA. sleep(ling time)) Y# O% |+ x4 L
B. yield()# k+ c" t8 E& T: F) f6 i
C. wait()
$ ~$ w, f& {1 ~% dD. notify()( l! B6 R% x5 I
23. Which method do you have to define if you implement the Runnable interface?8 L- ~' {$ Y9 ~' h0 v8 _4 A4 I+ Y
A. run()7 K/ w% y- w5 t0 y
B. runnable()
+ _8 @- C1 A( ]C. start()
! R$ D* r' j. F9 T% q2 f5 j, n+ @D. init()
: F0 W: Z/ N2 ] Q: E: o8 Y$ ?8 WE. main()8 w% k+ y& c% _0 N) \
24. Given:, C" x2 W7 J+ ?2 q9 Y( F$ v1 q
1. class MyThread extends Thread {5 G- e5 \9 u0 M, B0 n3 I
2. 5 e, D# V; v' m2 O: o3 P
3. public static void main(String [] args) {0 _" a3 b+ r# K6 q3 q- Q
4. MyThread t = new MyThread();
5 j; u, V4 J! o0 j5. t.run();
( F. M9 f5 O+ S& d; p5 G6. }
; p/ g7 c+ o7 u$ e, p7. 0 n! P+ g7 g' |/ c( [8 U7 z8 j
8. public void run() {9 i" n6 S- T" P( k
9. for(int i=1 ; i<3 ; ++i) {
}+ U" G, G# K10. System.out.print(i + "..");! W: d9 z# A* f, M* k9 t* T
11. }
8 b! Q1 s6 o j12. } f+ p) \1 V7 G/ |
13. }
6 Y1 G0 x/ f; r |7 }; C) d- }/ kWhat is the result of this code?C# X( i3 h! n# |# h, b
A. This code will not compile due to line 4
) @7 x- ^' R% \8 @5 W2 q4 _B. This code will not compile due to line 59 L) R0 s/ j5 w' v
C. 1..2..
r. ^" {' K( p3 w7 H2 }" ~D. 1..2..3..7 W: g( G0 M2 [% x' d
25. Given a local inner class defined inside a method code block, which of the following statements is correct?- V' ^6 T( T" D: l
A. Any variables declared locally within the method can be accessed by the inner class7 T. s) f3 N" ]. I
B. Only static variables in the enclosing class can be accessed by the inner class. ~. l# U5 a' A) m6 Y/ d6 q5 P
C. Only local variables declared final can be accessed by the inner class( {1 m8 m% C6 M, C+ |
D. Only static variables declared locally can be accessed by the inner class.) J/ T, t! g& H. s, m
2 q3 q( J9 ^" P
+ V$ T O6 k/ n) T. [7 K
+ P- X) h, Q. c* o: [
26.public class SychTest{ ' w# B; l- W1 b q; K
private int x; 4 r3 r! X3 R. D7 Y4 `; v& l. K S
private int y; 0 V* d$ b# _7 c$ v
public void setX(int i){ x=i;} 3 u ]+ P# G' u1 A# W
public void setY(int i){y=i;}
. a6 J4 m: Y8 w U- ? public Synchronized void setXY(int i){ 9 N9 r0 O7 Z" w! l6 S
setX(i); $ L- ~$ m( O6 _! R: U$ U
setY(i);
: D, O" ]' N$ Y) s" p( Q) j }
# [+ B9 C) H( w, z public Synchronized boolean check(){
+ C4 ^2 P+ e" N# K- R return x!=y;
1 y" t8 R: G. }7 m, y3 R6 x } % z$ U1 t, T9 @+ E, I9 z
}
4 Y2 w2 b) \5 {4 ^5 p6 ]. x Under which conditions will check() return true when called from a different class?
$ N1 y$ i. Y% o; p A.check() can never return true.
% \* q! ^8 `' C/ U# B. k. C B.check() can return true when setXY is callled by multiple threads. % A9 H1 N7 j! K6 p
C.check() can return true when multiple threads call setX and setY separately.
- _* y6 L8 `% o d9 X7 e r D.check() can only return true if SychTest is changed allow x and y to be set separately.
+ t+ h- V1 s5 K, n1 {; h- G& Q5 M2 X
27. 1)public class X implements Runnable{
$ U& I" n. O; l7 t4 N6 F+ o 2)private int x; ( F2 Y: V, j3 } q- ?; v. K6 C: C! g
3)private int y; 4 i Q! m" t( U3 ^ Q5 C
4)public static void main(String[] args){ 3 @* T1 L9 e+ D# L& Q- A6 E" E
5) X that =new X();
$ @# M! v# X& T 6) (new Thread(that)).start(); ; c. a: \' ]! M$ ^0 d3 m) \
7) (new Thread(that)).start();
% b( \) a. F# B- i6 u( G8 S }
1 i2 e6 K% m9 ]4 ~6 P: F1 c4 z 9) public synchronized void run(){ 9 z( t }" d7 {' }
10) for(;;){ 1 s" Q% s- D6 C; w- e7 e# A6 }7 [) G S1 G
11) x++; ) e% ], K9 F5 v4 `
12) Y++;
' s4 |; T/ T3 ]$ S% J% U 13) System.out.println("x="+x+",y="+y);
2 g! E3 G z* H# a 14) }
8 W' o# o/ p# L& C+ ? 15) } a9 J) X* e; Y, t
16) } $ v: t( H2 c- g4 ^: ]- M
what is the result? 1 k5 J& {3 _) P6 c
A.compile error at line 6
{8 R/ y" }2 B6 r8 O& b B.the program prints pairs of values for x and y that are ) {/ A6 v4 z: L
always the same on the same time
7 P$ ^1 ?6 f/ E" y
" X, Z" e1 j! S1 E8 L6 O28.class A implements Runnable{
- T5 X# p, E" {6 f int i;
4 n5 w* b: K6 |* K! Z public void run(){
2 L# y$ H, Y) \4 i6 w try{
2 z% w" {( |" f& h! o( _! E3 x$ d. Z Thread.sleep(5000);
3 G% a3 u; \7 }. ~ i=10;
! l- s# l+ h+ }0 A E5 g& B }catch(InterruptException e){} 5 s9 w7 Y5 F( m7 ~
} 1 Y% y# q* ]4 E# s" G
}
4 a1 r3 b5 o0 R& a( q `" g public static void main(String[] args){ ! b) A& t* X& M, A. K' T5 p4 Y
try{
+ G0 n6 B6 s- C0 ~7 W A a=new A(); ) ~: ^* w0 t4 z' m9 r' _7 A7 L
Thread t=new Thread(a); 2 Y9 o5 F' H+ z& E
t.start(); 6 r* x k9 a7 I1 a- B% k
17)
+ H# q7 w, K, n6 i4 f' g" n9 X1 Z1 m7 A int j=a.i; 1 H; D+ Z# M: M- S3 T
19)
1 C9 x. a, n! g; i: f/ z }catch(Exception e){}
2 R1 r! m+ w" I! |. U3 a" ^! l } ( z' d# ^1 e2 t3 z5 H/ d0 w
}
?- B1 o8 t. @+ Q- ^ what be added at line line 17, ensure j=10 at line 19?
6 J& O' R3 V! O& G: A; c$ n6 R5 E A. a.wait(); B. t.wait(); C. t.join(); D.t.yield();
% o- p% v4 H% U# c+ I, \ E.t.notify(); F. a.notify(); G.t.interrupt(); 7 ^% e) |8 Y/ e9 b, w/ U
29.1)public class X{
3 T W% m- C+ y4 {9 P& l- b! h 2) public static void main(String[] args){ : Z$ W3 m O) A& \# A3 O- j$ H/ Y0 F
3) String foo="ABCDE";
) g7 ~- i( O1 w 4) foo.substring(3);
; y( X2 y: V5 K 5) foo.concat("XYZ"); 8 `5 k! n7 ?/ H% |1 h5 f
6) } 2 p p+ r% s, m
7) }
* l6 v. [; ]. [" u: S1 l* { what is the value of foo at line 6? ^. ?1 J& L& B. J4 }
30. public class Test{
0 }7 h/ C( [0 Z( A) x" x& P. } public static void main(String[] args){
+ C! C4 A1 F& q m StringBuffer a=new StringBuffer("A");
+ \8 i. l7 G1 B# ^ f2 v StringBuffer b=new StringBuffer("B");
& R' W p: D6 w% A% H" z operate(a,b);
$ g* }6 o+ R! |2 J System.out.pintln(a+","+b);
) Q2 C( S* ^4 S5 h- U" u0 t5 J }
; M/ C: }1 A, ^- Y public static void operate(StringBuffer x, StringBuffer y){ 7 {9 o1 j* R8 x8 }9 v# G; \$ s
x.append(y); 0 S; v. }5 i0 {- ?. E
y=x; $ q7 ~% v* X% T. ?# @
} / R# @) V# j8 |
} & E4 N; e8 |. {
what is the output? |