Sample TextJava培训考题
4 k9 c; Y5 b3 H7 t2 _7 o1. 给出以下程序:
9 }2 L( I% n5 x4 D4 n1. public class Colors {9 t; p4 F' Q4 y9 H
2. public static void main(String args[]) {
: q% b( W, y" q# u V3 e3. int n = 1;
& Y/ y# x- f" u$ L. b" m' o4. System.out.println("The Color is " + args[n]);# i9 }& }% P; E, a& ]$ ]
5. }) [( m9 z! E1 U, J# H* q2 D
6. }( n, P+ i- a. R' I9 {9 S
假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”& e6 D. h7 t' E/ N
A. Colors red green blue yellow" J/ f6 S$ k' [8 O$ f
B. java Colors blue green red yellow6 S( u1 A2 }0 }& t1 I: d3 D8 v
C. java Colors green blue red yellow
. w# c+ I" V2 r, p ?" d2 M0 HD. java Colors.class blue green red yellow
$ Q8 k4 ?% Y( W/ qE. java Colors.class green blue red yellow
! D& q$ [' N6 x. C+ H* w2. 读程序:% P1 P+ a6 ]6 y' W0 ?
1. public class Test{6 ~* y t6 x: V' _' P' J
2. public static void main(String args[]){
) \4 ]- d4 T% ^* w* f3. char c = '\u0009';6 q0 Y# d7 u. ~0 ]( v1 K
4. if( c == 0x0009L)! x+ w# o; a$ ]3 C$ F
5. System.out.println("Equal");
& G% l+ J) z3 J8 R6. else System.out.println("Not Equal");' O( y6 A! \5 x3 X
7. }4 a( B5 R3 ?3 ?2 u
8. }' Z0 L* ]) }! t. j& v' z& k2 m" d8 Y
当编译和运行该类时,将会发生什么:
( ?# ~; v/ N- UA. 程序因为第4行将出现一个编译错误4 V l& |0 v' o* ` r+ J
B. 程序因为第4行将出现一个运行错误9 E& }% E* t& k0 G, \
C. 程序因为第3行将出现一个编译错
s5 Z: |6 E3 x2 tD. 程序输出”Equal"7 r8 N' n# i% ?7 B
E. 程序输出"Not Equal”# x2 H, G" {8 I
3. 读程序:, w5 V1 q/ ~$ d0 b5 }( E! H# ~9 E. z3 F
1. public class StrEq{1 z& S8 _7 F: x. | {. g! h
2. private StrEq(){* w1 E1 R' l* {* U6 v2 W3 h# G
3. String s = "Bob";; C: `5 ?4 J- C: `
4. String s2 = new String("Bob");
( E: v" b6 o) \, N5. if(s == s2){. v2 R( v% O( p( [; s
6. System.out.println("Equal");
* T5 V+ d+ F) P) }/ u9 w, u7. }
5 u8 q* M7 t$ M; W; o4 l8. else{
' A) g( s6 N( t! {4 L0 c8 k9. System.out.println("Not equal");. P* F6 _& Y, j8 f2 H$ k
10. }% V8 v, Z% U4 M4 Z7 R0 q+ b
11. }: R: K1 E3 f2 z3 a2 `
12. public static void main(String args[]){5 V+ j6 P T4 z
13. StrEq s = new StrEq();6 z3 d9 D/ O+ e+ R) j3 v9 T1 p
14. }: Z% i! x0 o4 h- T4 l
15. }
9 g2 H+ ^/ I. K2 c- c% u: A1 a当编译和运行该类时,将会发生什么:
3 t: ?2 M( t6 d" |A. 程序能够编译,并且输出“Equal”9 H! [1 @9 \' W9 l2 [
B. 程序能够编译,并且输出“Not equal”
# R. E* z5 X( ]( yC. 程序因为第2行导致一个运行时错误
, Z2 N- u% X4 K" VD. 程序因为第2行导致一个编译错误
0 q: m! b7 s2 F3 ?4. 以下那个赋值是非法的:
2 `$ f5 p5 X7 k0 a5 r, \' _A. long test = 012;4 ?3 @ A h. z! O# |
B. float b = -412;2 F+ A1 u/ B5 A0 m
C. int other = (int )true;& ?$ }/ {. |& I3 s: j; P
D. double d = 0x12345678;( P: W8 B( Q2 \) l' [ |# q/ ]
E. short s = 10;
6 B h9 U5 m( H8 L# e- H5. 读程序:
! `- p& y+ ~% s; ^2 ~8 @ J1. class CompareString{6 j4 Z) i6 M: N! M6 u8 E5 U- E
2. public static void main(String[] args) {
. H6 u9 s1 K/ E- q3. Integer x = new Integer(5);
& z+ N+ e- M$ U6 P" @4. Integer y = new Integer(5);
: [" {; f# V8 Q; S& f( T5. Integer z = x;- w( t, A) x$ H1 U
6. if ( ______ )7 K! @7 D. X1 Y! h* u
7. System.out.println("true");
2 S" e$ W6 v) i6 ]8. }
* A/ o9 ^& v, J {9. }( f3 _) n+ ?- C) l' `
以下哪个选项填入第6行后,不能输出true:+ _& p/ s, w( `
A. x==z3 k0 t F2 o& L& V3 i' x
B. x==y5 T) t' R6 Y' g0 c, G; u1 U
C. y.equals(z)
' f, M, {1 B5 UD. x.equals(y): _5 [; U, |' ~! D9 F
6. 读程序(双选):7 ~2 ^; ?* a) Q8 j( p" i$ F' M
1. public class Declare {
0 _; D! A6 r, v Z; i7 p% u2.
" f" w, V |5 j. _1 {3. public static void main(String [] args) {
: c# T# j* l; ?" t5 W( N: k7 C2 a4.
2 b q s1 h. e7 g) c# m( s5. System.out.println("The variable is " + x);
; K) z6 w! \9 b3 H9 e6. }
3 K4 k2 y! t3 R7 r7. }
( \2 ?8 @% p9 U4 h. N以下哪个选项中的代码可以使程序编译通过
& ]9 X' j) n1 P- sA. 把“int x;”放在程序的第2行
* |$ g( L2 [6 c5 s- v" WB. 把“int x;”放在程序的第4行
0 i$ X( V" c" O% G0 r6 F& iC. 把“int x=5;”放在程序的第2行
$ D% l8 V0 }4 G% |2 jD. 把“int x=5;”放在程序的第4行 x4 o" ~9 H0 c) I" r! O* Y
E. 把“static int x;”放在程序的第2行
" V+ }/ m* Y) V! i9 Q @$ B* l% d3 _
\4 b4 l5 n+ }) Q: c) ]! X* J- t9 Z2 L% r
7. 读程序(双选):+ U! f; U0 w7 ^6 B4 I
1. public class Child extends Parent{
0 H$ D4 b& v) F: q9 D# S2. int a, b, c;. x3 @- f! L( |4 h/ w! y
3. public Child(int x, int y) {$ p& ~* R3 ^$ `4 z: q! R* n5 A
4. a = x; b = y;' E' z2 {1 D8 s: l
5. }; T) Q1 l. K: [+ \% y. R5 Y# [
6. public Child(int x) {% w! F. w" u G+ e* O
7. super(x);
/ W( i+ m% P) R# V0 M* c8 j8. }& ?, w5 Z& `* w+ _% _/ c: ]
9. }
5 A, p! L; H' g; P2 L为了能使该类编译通过,下面那个构建器必须出现在父类中:+ ~3 n0 T0 _. ?# `/ k% ]4 i- i6 @
A. public Parent(int m,int n)
' I5 M2 R+ A7 r; }B.public Parent(int m)" R* \, g. t6 D
C.public Parent()$ u: u$ M! Z- ^% [( k) f/ `2 }
D. public Parent(int m,int n, int o)
+ k+ j: U; n# O8. 读程序:; ^5 g2 {+ P0 H. ~% X, r
1. public class Derive extends Base{
: f: G0 r/ E$ ~, e, Q2. public static void main(String argv[]){, S/ b, M- _; w( A
3. Derive a = new Derive();
) p( x( Q4 }9 c& `; M: e4. a.method2();3 r5 Q" G" w. [& v4 Q& j' q+ D) @$ R
5. }- p1 U% E/ Q1 z& u( K4 \: v
6. public void method1(){& [9 V4 M" l, W/ g: ?
7. System.out.println("method 1");
/ z/ L' f: C0 P8. } ; Z. J( l) }6 e! h9 G
9. public void method2(){
' M5 k, c) w- ~ v+ l( ]. k10. method1();
, v2 `; b6 S J( x' F, w11. }6 z* p1 H/ @5 ]7 t: t
12. }
S2 E, J( P, y0 G u13. abstract class Base{
8 B, }0 }6 z( h2 K- @14. abstract public void method1();
" _; E e5 K" ^0 a15. public void method3(){
u2 D9 e0 Z; c, c' B( u) P2 Z% `16. System.out.println("method 3");& R8 H3 \1 n1 B
17. }
4 U+ L* B5 Z! \4 F, g}
$ _9 [+ v. l! F* p0 j1 U当编译和运行该类时,将出现什么:
! R# z& K' S, vA. 程序输出“method 1”
: N0 M" H' W4 KB. 程序输出“method 3”
! h$ t1 J& g* O% X2 UC. 程序因为第15行而出现编译错误
# u# K9 d! D: ?" l6 m& f6 W% c! OD. 程序因为第15行而出现运行错误
: c" k2 F$ W8 v3 d. ]9. 以下哪个接口的定义是合法的:
( l: R3 P1 n0 a# r) S3 S/ ]. FA. public interface A {int a();}
, d0 o5 F) U* vB. public interface B implements A {}
) g5 y, l! l9 v3 JC. interface C {int a;}+ {9 W$ y' I8 {% M! P( P
D. private interface D {}/ ?! y: b4 G! ~$ g# L) w& _5 v. v9 d
10. 读程序:: Q* B/ J) J) `; a4 E# p
1. //File SuperClass.java2 O8 X! y- v) ~; |/ ^. E) J
2. package MyPackage;) k; y) [) \) V$ r
3. class SuperClass{6 c: ? Q, k9 f3 _4 c' C
4. void myMethod(){4 `% o# b$ B/ G1 O# E; F: G7 ^- P
5. System.out.println("SuperClass");
7 e* {3 w: g5 V. k+ L( Q6. }
' g0 Q% o0 j1 ?4 W8 W7. } C/ M6 H$ G+ N3 @; R4 T
8. //File SubClass.java
; h; N U% b8 y2 }$ Q; z/ }" ]9. public class SubClass extends SuperClass{5 |# \2 M: \2 W7 T, q! y
10. public static void main(String[] args) {+ C/ ?6 H: g9 c
11. myMethod();
4 m6 {) S$ Q% j- G9 R3 O# G/ X12. }
& o. a! v; v' i13. }" T% A4 _/ ?; t, `" \
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:* z7 p3 n2 _# L# \1 P* s
A. 两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”
8 q5 e6 O- u/ w! @B. 两个类都回出现编译时错误
; P4 j! }! e& Q' T) f: K1 BC. 两个类都可以编译通过,但SubClass会在运行时出现运行时错误
7 L3 r7 W& Q, U5 ?4 X( q7 vD. SuperClass.java可以编译通过,但SunClass会出现一个编译错误* ?6 T8 L1 A! c$ S J$ ~
11. 读程序:; [/ T. F |7 x# Z, J0 S
1. public class Test{
% k* t8 a4 R$ v! }5 R; l' T) X2. public static void main(String args[]){8 ~$ Q; v' a* E7 M: t! y6 ]0 j1 \ a
3. int[] i = new int[5];
2 }. b6 g- T" P% K! {: o4. System.out.println(i[5]);- ~9 U" ?7 w' @6 S5 R
5. }
( V! J8 d+ Y- B" n6. }$ D8 l6 a: G- p' C {
当编译和运行该类时,会:* m2 W5 _: k% P8 f& j3 f. N
A. 出现编译时错误
1 F7 H5 G4 K" v4 }B. 出现运行时错误0 n0 x* x. d+ ^# Z' f$ |
C. 输出0
; M5 ?1 ^! X! Z0 U/ fD. 输出null. c9 c. D$ F& I0 q; C; Z
12. 以下哪个选项是正确的数组声明或初始化:
. _& e& T# f8 nA. Array sizes = new Array(4);. p" G" s( P! a
B. double [] sizes = {1, 2, 3, 4};
* L& b8 w. j; P8 XC. int [4] sizes;* Y7 G5 v% N- q2 U
D. long sizes [] = new [4] long;9 q( k! M, _* p4 C
13. 读程序:" E5 y7 A' ~6 @' o5 @+ S
1. public class Initialize{# Y3 ?/ L$ I! v" i& a/ Q4 x& A
2. int x = 200;
( ^) f2 j/ y2 d w9 ^' }; F# b# C3. static {
9 p, p! d9 k: d" y* w9 w$ O4. int x = 100;
* [0 z; x6 S( |+ f5. }
. d/ k0 g( H5 i$ q6. public static void main(String[] args){8 F D& G4 O% t% |' n# w3 i1 ?2 s6 n
7. Initialize init = new Initialize();/ t: h6 J. m. w0 [: A
8. System.out.println(init.x);
+ o3 P* H8 g J" J5 r# }9. }
: j" j- R) J5 N% U* c4 C10. }4 B' q2 O7 g" G* @6 M- O1 y6 R( w
当编译和运行该类时:
. c1 N0 W8 Z# Y) c* jA. 程序因为第3行产生一个编译错误
* p" L: H% A0 v; eB. 程序因为第4行产生一个运行时错误
6 B0 j. T; p: j! C9 TC. 程序输出100$ Y: }% n* a) F' g) f
D. 程序输出2000 m& ?" g3 {5 E4 J
14. 读程序:
9 N7 X( U7 n& h1. public int abcd( char x) {
! L5 ^2 x4 s7 t+ r2. if ( x <= 'M' ) {
! e# p: {$ H8 w7 |" ?: L, i3. if ( x == 'D')
5 C) g( v) Y, m; c+ f4. return 2;
0 M% ?; K4 N( t5. return 1;% _ _( W6 s/ d6 p9 i; t0 a7 q3 O
6. }
# p7 }* s: \# z# b8 @7. else if( x == 'S') return 3;
9 x5 V2 q8 s9 ~8. else if( x == 'U') return 4;
' p" ?# l5 V& X: H/ b9. return 0;0 }) c$ v8 a; N# ]+ ~ e- H, s
10. }& j3 W! T, f5 b" S) |; |# S5 H/ q
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
/ F' z8 @' P. Q0 v, yA.‘X’
" R4 V6 S9 d4 `: @ f# ` K6 }B. ‘A’
% V3 P$ ]1 E$ M1 {2 NC.‘D’- [& i: U$ O9 G& Y& H
D.‘Z’6 n/ K: y" p k. w* I
15. 读程序:
8 h4 z. k/ N& `, p" V* G1. class TryTest {
* `' `2 T) {7 Q4 Q# A/ [/ G2. public static void main(String[] args) {
1 S* |5 n! |9 N/ q q/ X f( |3. try{
, v9 [0 f, q/ b& }: I4 x, A, Z$ |4. System.exit(0);
) C8 t" h" V+ ?5 g) w5. }4 Y2 \! p" k% Q3 w0 [ }; u
6. finally {
% n; E+ \5 Z; L) E: T1 V7. System.out.println("Finally");$ e* K" U! O: s: b9 g9 n' R6 f( p' F
8. }
' m$ n6 p- c! F7 k& s8 c# P5 A2 T9. }
2 n# v P0 H' T2 ?10. }
& q" @& s' d' v5 K% T6 f% r$ {当编译和运行该类时,将:' P1 x3 x8 h/ m, z- n- e
A.程序因为第4行出现编译错误
8 y- R% \& C( ]8 e; \5 s4 tB.程序因为第4行出现运行时错误# O+ n! Z ?9 M5 P9 R8 s! }5 g8 V) C
C.程序因为第6行出现编译错误: p1 O1 z" k6 } D
D.程序因为第6行出现运行时错误! h7 @! M+ A, N
E.程序输出“Finally”
( P; V/ y2 E6 @( T5 X9 \8 jF.程序可以运行,但什么也不打印5 v, \! X$ b" D4 X
+ d( [. ~ |; s4 V( j' A
16. Given the following variable declarations:
/ U9 D/ F: l! O# H+ H$ `Boolean b1 = new Boolean(true);
7 ]9 y) h% {, N3 o6 Y, m5 V" I0 P" bBoolean b2 = new Boolean(true);& X o! x, F5 y9 P
Which expression is a legal Java expression that returns true? ) Q2 Q8 ^7 H1 v* H( E' c/ `
A. b1==b2; ^9 n4 t R$ U) g$ K; N, V$ |' y
B. b1.equals(b2)
1 k' e+ V( L# q3 ?$ iC. b1&&b2# F K7 V% b4 ? ]; S! i9 l# ~
D. b1||b2' x0 E4 S$ `7 g5 `5 t x% @% d
E. b1&b2 [. Z+ N5 G3 z
F. b1|b2
; R: c: H- P' \17. Given:
- p' ^3 o! Z a1 r1. public class Employee { B; A+ o+ i0 y$ Y9 q" [
2. " M4 ~% Q" _& s$ n
3. }& d& k# O* s$ H) e
4. % }. s3 J7 Q7 X! [1 f8 Q
5. class Manager extends Employee{0 q* B/ M2 g3 f' O* B
6. }4 X- _ K" d7 P: O9 m1 w
What is the relationship between Employee and the Manager?6 e, Z" \; l3 @, X- K5 V
A. has a
4 z, I* u2 `: n F( w5 eB. is a$ g. T4 I* Y( V3 F, j+ v l+ y
C. both has a and is a# ^# O' ], Q! D. K0 |% e J0 M. K2 H
D. neither has a nor is a
2 n8 ~+ Q+ b2 s3 `4 v2 K- [18. Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?
2 w" i$ N7 C# g q7 z9 Z2 SA. BorderLayout0 H& `' R. V% Q; {& U
B. FlowLayout1 B2 w; R2 E2 w
C. CardLayout0 x" `# g7 R* Q: f7 ]1 X5 |
D. GridLayout; N0 R9 U. M g2 U% r" l
19. Which of the following AWT components can generate an ActionEvent?6 M% B- R3 v1 u/ K! ~9 v
A. java.awt.Button- ?1 l! U. @/ K2 b1 W+ Z* o
B. java.awt.Panel
0 E6 i3 S3 X5 ]% ~6 j& HC. java.awt.Canvas! _! J& I! n/ h6 L- O
D. java.awt.Scrollbar
: s& u& {" |4 J$ O' P20. What kind of Stream is the System.out object?2 G1 Y" N: C- S; A. ]& L
A. java.io.PrintStream
( y/ d9 O, _% q; v) fB. java.io.TerminalStream& F% @# \% n' e
C. java.io.FileWriter' y' i' |+ x/ H1 m$ h
D. java.io.FileWriter! q. G, k' R: \# _ W: f1 a
21. Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)0 f" |. z ?8 P3 o( }5 q( s; Z
A. java.awt.event.FocusEvent
5 x. U/ M! U# w: J* }+ s0 t; xB. java.awt.event.KeyEvent
- F* z% ^8 _' v: q) h; ` oC. java.awt.event.ItemEvent# C* o' T6 c! ~4 {
D. java.awt.event.ActionEvent
- J/ D1 C( u5 u1 z% I22. Which of the following methods are static methods of the Thread class?(双选)
. J4 C0 a! w0 |# cA. sleep(ling time)
6 v: t/ e3 r* L5 ~- K- o6 [B. yield()
3 `# a, G2 t8 v4 ]C. wait()1 y7 i. ?. X( _4 q0 R: o
D. notify()
3 E3 w" z1 m. W( H. m1 J. C23. Which method do you have to define if you implement the Runnable interface?
- ^8 E P/ t; ?A. run()
6 i2 K) Y; ~* i2 p! dB. runnable()
: G) \9 }/ o5 U$ U. o( \C. start()
# a- ^7 U3 B8 R6 N) fD. init()
! L) c! c" b$ C/ SE. main()
0 U! D6 h B1 v: W; U3 |5 s3 P6 z24. Given:3 ~* R/ O; t% r4 B
1. class MyThread extends Thread {3 `* W$ x6 X; W! Y
2.
6 A# p/ c6 Q. Q3. public static void main(String [] args) {
& ~ m) [* z% T) e. G1 i2 g4 u6 b4. MyThread t = new MyThread();
| N% c# C. ?3 [+ H5. t.run();
' S! M& {# y0 P/ l2 @0 s6. }6 K4 A8 b9 ] F8 A. Q
7. " V W1 `# t8 s7 \
8. public void run() {* z% o& R5 u2 P- Y/ U. P8 E
9. for(int i=1 ; i<3 ; ++i) {
' s2 K# ~* _* `& z; Q10. System.out.print(i + "..");; L) s8 e- e/ B [$ F' p; J- a
11. }
; j* k" b" i# h) E$ I. `7 u$ e12. }
! u1 S% v0 ?6 Z4 s2 u+ s/ P! E& E" y13. }5 k, s6 x& q8 Y p( p
What is the result of this code?C
' r2 E; h2 G) `/ J- `A. This code will not compile due to line 47 f3 M' B7 ^* g, |* i3 q g' o6 n/ H
B. This code will not compile due to line 5
, x6 ~4 ~! C9 DC. 1..2..
2 Q0 I0 s" N, J' iD. 1..2..3..% w# m; c* P4 p* p3 U
25. Given a local inner class defined inside a method code block, which of the following statements is correct?
0 ?! b% c1 O% W, d' e: ]A. Any variables declared locally within the method can be accessed by the inner class2 _8 G3 a$ |- p. M5 e U
B. Only static variables in the enclosing class can be accessed by the inner class
; J; l& L" M5 C/ B( K" l5 c& PC. Only local variables declared final can be accessed by the inner class" @$ P3 q2 V1 ]) `8 v
D. Only static variables declared locally can be accessed by the inner class.) f; f2 |9 H! _' o- l0 s" S: r
6 @" ]) c6 }5 \5 p4 b0 h
3 p, V! I, X; P3 g/ Y
& f# r7 J6 Y$ V$ Q5 R, ^6 {5 Y26.public class SychTest{
+ j# q/ C0 h" E1 [ private int x; 2 T! X6 I$ O, J' n8 U
private int y;
4 ^0 y% c0 ^% ]' E0 B6 y public void setX(int i){ x=i;} : J) y e" P" r
public void setY(int i){y=i;}
+ e4 c/ V4 U0 B public Synchronized void setXY(int i){ - D2 u. t2 ]! E8 O) f' b
setX(i);
$ E( ^- h9 A9 z+ D- {% E, w setY(i);
0 i S, i: w w4 `( G5 u' k }
G2 Q0 @- h0 L ?, @8 e public Synchronized boolean check(){
, L) e5 P, f, p: ^7 C; Q. D% M( Q$ l return x!=y; & _6 c d5 v& o" b* S
}
2 N7 ~% g+ g% R. ~. x& q$ m } 6 i2 B, u% O) h* Z& b
Under which conditions will check() return true when called from a different class? - c# k* F6 h( Z7 s2 M1 P! ]2 V2 g# v
A.check() can never return true.
) l. T& ~8 B: U8 Z B.check() can return true when setXY is callled by multiple threads.
( V7 T Q' Q: l, L. |: w7 ~: X C.check() can return true when multiple threads call setX and setY separately.
9 t4 J; N- H- n/ @& P9 l D.check() can only return true if SychTest is changed allow x and y to be set separately. 8 n( j1 G* G% a, U" o; T" F
, \7 |& e$ Q" N27. 1)public class X implements Runnable{
( ]6 P+ ~( }' X+ q% E+ ]0 _, L3 Z 2)private int x; 3 {. s7 l. b8 q4 f# z, J# s
3)private int y; 6 m' V% J- x1 z
4)public static void main(String[] args){
! K! R" W* _/ T4 U3 K: j 5) X that =new X();
$ B3 L f3 ^9 ?! v 6) (new Thread(that)).start();
+ `* I# Y& I1 l6 K* a 7) (new Thread(that)).start(); $ ?4 E. N8 L& w& ?6 ~/ W- ~
}
3 F3 V+ O Z* D6 l 9) public synchronized void run(){ * @) ~+ b- E& A( D$ d, ? H) [4 T
10) for(;;){
( O4 E: ?, b6 \% p" | 11) x++;
2 h4 ^8 A% X. e 12) Y++; # R3 ?# `4 O% d# ]
13) System.out.println("x="+x+",y="+y); 6 j; V8 p7 i' y
14) }
- N$ x; E8 M% i. B: w 15) }
2 k& Y2 t9 s/ E( b7 B: K5 J, f 16) } # N) b6 c. o) M5 M$ e
what is the result? 3 G! m1 @* S$ m# ]0 A* v3 d K
A.compile error at line 6 8 E0 ]. @9 C. a4 o
B.the program prints pairs of values for x and y that are " @, q$ A% z/ ?% Z! L# X# b
always the same on the same time
, J) q! c- H+ ~9 i: M+ Z' E% I2 j- o+ @; {
28.class A implements Runnable{ % R" f. W- S! U
int i; ! ?5 @, C q: \) j ]* q4 Q& }! t
public void run(){
% z. V' X$ W. r7 o. P% q' G try{
/ N) W. ^' H& y2 H$ g: H Thread.sleep(5000);
( p2 q& B# ]1 T* n w i=10; 2 N+ J; @8 O7 }- Y# ~ a. ^
}catch(InterruptException e){}
( t! t; \8 N# Q* \; _ }
( k, M, F0 j7 }0 H. D, j- }; @+ l }
! o" U; q$ l t public static void main(String[] args){
p' j+ t- \8 T: Q/ G try{
. S9 x+ b& M! } A a=new A();
# l" E) `- n; M1 R) v+ k0 {4 \ Thread t=new Thread(a); . p. @1 T: [& J5 B1 G7 W, v
t.start(); , B" z" X9 R$ i- M# e
17) ; U% F5 j8 f5 r$ N U( E
int j=a.i;
* S3 a" _/ a4 S. O: A 19)
- V& K1 [" W+ N3 I4 b }catch(Exception e){} 3 B3 o2 i: o2 t9 E: w
}
( @' l* |3 N" d6 N }
1 ]1 N' [ _: S! s/ F+ W# ?/ X what be added at line line 17, ensure j=10 at line 19?
* k* E$ u$ x8 Q6 k A. a.wait(); B. t.wait(); C. t.join(); D.t.yield();
1 r# Z [: T: T( h, F E.t.notify(); F. a.notify(); G.t.interrupt(); $ z+ J( o$ m: l
29.1)public class X{ 7 S3 P- y% v- k% F- N2 @, L
2) public static void main(String[] args){
( }. J( n& S2 P* X! b" l 3) String foo="ABCDE";
; H. b$ i* b. g6 Y$ S 4) foo.substring(3);
' c" o) H' k* { 5) foo.concat("XYZ"); T, @' r) U0 T
6) }
, q8 A% u/ G" k- m 7) } , P( N5 }( V0 N `3 G, U% t$ O
what is the value of foo at line 6?
( T& K* h% T& E: N30. public class Test{
) Z$ @6 Z. ~9 Z+ ~' G* x, z public static void main(String[] args){
! z( Y, b5 u/ D StringBuffer a=new StringBuffer("A"); ( [7 p0 n9 m. T- S( P
StringBuffer b=new StringBuffer("B");
6 l2 [! Z& M! _: \" x operate(a,b);
9 {7 e& Z/ k2 X* G( P; {# s System.out.pintln(a+","+b); " J5 ?% v" ?0 e a! _' u; }' w3 T
} 9 ^# v2 I$ h+ E8 E0 E+ a
public static void operate(StringBuffer x, StringBuffer y){
) e" m! n( v. E- p4 O x.append(y);
6 M$ d# Z* A& M y=x;
( Z7 m2 z# x; b3 ? } 7 r1 ] m6 q- J( c9 G4 f
} / H' k. n% _! X& \# c
what is the output? |