Sample TextJava培训考题" j; q5 T' [$ e3 q
1. 给出以下程序:
) u/ [% P, ^: P1. public class Colors {
7 u* ]! V" Q# ]( f& p# V2. public static void main(String args[]) {
6 t$ c% n1 z+ f9 ^# H4 t3. int n = 1;
k) t6 }) Z6 c* M+ |3 O* }3 _* Z6 \4. System.out.println("The Color is " + args[n]);$ Q2 h7 B4 _: \* ]4 v8 S% ~
5. }
6 Q. u* V) m8 p3 l1 v2 K* Q- s6. }6 O9 @0 [ I: V& Q0 v9 h/ A% D
假定程序已经编译通过,下面那个命令行可以输出“The Color is blue”. Y0 q/ x( P0 |
A. Colors red green blue yellow
/ ?& _, `1 A" ]' q* a1 L2 cB. java Colors blue green red yellow) }: U# f: q" S v% N. G; k! U
C. java Colors green blue red yellow
# p. K3 t" k' Z9 F" F7 sD. java Colors.class blue green red yellow
7 F, M# P/ ^! a' y! k; kE. java Colors.class green blue red yellow
_6 t) r7 R8 w1 i2. 读程序:* j$ n: l* I1 p5 @* K, j
1. public class Test{/ O3 L W1 b, M3 \% M& m
2. public static void main(String args[]){! C6 S5 j6 i4 h# L) {3 m
3. char c = '\u0009';# M! ]- h( ~" Q; w
4. if( c == 0x0009L)
, m8 d! O5 ?" v; K j5. System.out.println("Equal");. i! l+ v' B% g) U: I; W( e
6. else System.out.println("Not Equal");! Y. T2 y9 w# A- K7 J U
7. }
8 v9 K$ p% Q! {" W9 ^8 R% s8. }
4 @" N, ?% b' B$ v当编译和运行该类时,将会发生什么:
- m" Q/ y4 y& k* O9 vA. 程序因为第4行将出现一个编译错误) Q! {+ x4 {* W% n7 [6 X
B. 程序因为第4行将出现一个运行错误
- ]. B4 H/ T, j u. x. NC. 程序因为第3行将出现一个编译错
$ B2 e* T& U8 T7 kD. 程序输出”Equal"8 a. b7 x+ B4 q8 m. A8 x# y" _
E. 程序输出"Not Equal”
+ m! K) U3 H i+ B( a1 e& f3. 读程序:4 w6 @7 k+ P0 ]: g. g
1. public class StrEq{
/ `/ [! v$ ?* a8 t" W, W/ N! H2. private StrEq(){) Q) r5 E2 S: Y& U+ j0 n$ b
3. String s = "Bob";
6 H7 ^+ a5 P6 W0 h! a4. String s2 = new String("Bob");5 k7 S- Q2 C+ h X/ x
5. if(s == s2){
3 J9 {7 `& O5 c7 e3 u. ]* S6. System.out.println("Equal");8 \3 w" `! F5 o2 A
7. }& r; | C. S. j% d
8. else{
0 c7 Y3 {, w6 v! g9. System.out.println("Not equal");' [" n3 u r/ b1 e( z* H
10. }
, U+ |; G9 D* v6 B4 [11. }
' b! j3 y. x$ t7 p7 L1 O2 j. c; K12. public static void main(String args[]){7 M' H) p) j( B
13. StrEq s = new StrEq();4 l+ A+ M, e* @2 S. ]% ^/ Z( y
14. }
' ?& l$ c+ D! I15. }7 W- a% d) t ?1 y
当编译和运行该类时,将会发生什么:
8 l1 A: ?$ \4 C$ d! D3 gA. 程序能够编译,并且输出“Equal”* a d6 X8 B2 c8 ?
B. 程序能够编译,并且输出“Not equal”
* G# [1 A* E0 M- ~* V$ f5 hC. 程序因为第2行导致一个运行时错误
* x9 C. M0 L# S5 y- e+ [# ^% ?3 wD. 程序因为第2行导致一个编译错误
5 [0 `5 ^% V8 z8 ]+ N& P4 `0 D4. 以下那个赋值是非法的:
3 P7 ~% D( i) }- B6 W1 f# T5 ]: ^0 EA. long test = 012;
2 q' D& Q9 i; g* V: X; D: ^4 VB. float b = -412;( I _( S g0 m I/ s4 e
C. int other = (int )true;6 _ k4 Q$ i7 p/ c4 E
D. double d = 0x12345678;" ?8 i6 H* z. ^9 @1 X2 n/ D
E. short s = 10;
; S4 f# r! Y/ I6 ~) u5. 读程序:" I- p; W; g9 t1 o9 @
1. class CompareString{
& H* z) Q) n0 K' e1 Z, Y2. public static void main(String[] args) {
& I$ l3 p6 K' X( S" Q3. Integer x = new Integer(5); ~: k0 O% a8 I9 h7 }
4. Integer y = new Integer(5);% m' x, n8 N6 a$ u- R$ I. b
5. Integer z = x;7 d% e4 u4 G! ` J1 J8 f
6. if ( ______ )
3 [* i2 U$ \1 L; `/ U" b7. System.out.println("true");
6 N6 A& |/ R e' E1 H8. }
# L7 w" H) A+ v# a' m b9. }& p. W/ e- J3 W0 x/ w
以下哪个选项填入第6行后,不能输出true:
, v1 }1 A. [( m" C- cA. x==z
: y5 V- } @! v9 p7 E3 XB. x==y' Y; C+ \, n3 I+ E5 |* W
C. y.equals(z)
; p) n2 ^1 T5 e# U7 ]: ~D. x.equals(y)
% p$ q4 C- H! F* u0 t: m' J6. 读程序(双选):5 t9 f9 i4 S3 u; F- z
1. public class Declare {7 ?5 P4 n( B+ e( w( { z" g* m) a' j
2.0 d, S" A8 j. v( [# U
3. public static void main(String [] args) {# D Z3 z# ]; o$ L! {5 C
4.
" _, n# Z) X' ]( Q, c& s5. System.out.println("The variable is " + x);. c9 w2 t: b$ ?- }
6. }
' u$ R l; |% k' B9 e* ]7 C7. }
0 r2 D3 O2 M0 Q( t以下哪个选项中的代码可以使程序编译通过" u" ]) Q! n6 p
A. 把“int x;”放在程序的第2行( m! y: \, o# p5 U/ O8 q
B. 把“int x;”放在程序的第4行# \' z8 k2 t r
C. 把“int x=5;”放在程序的第2行
. D0 c' Y, n, i, T& |D. 把“int x=5;”放在程序的第4行
2 \ m: {) q1 q! x" y' r. T3 AE. 把“static int x;”放在程序的第2行
s& O/ J5 N+ t9 s! Z/ v' k0 Y" _0 E+ A" S' b9 ]
0 I y1 S- v6 V4 T
9 E! I3 s7 E, T( D0 T3 z
7. 读程序(双选):, T, T, c, q* F7 O) d0 H+ N
1. public class Child extends Parent{
3 e9 G7 _% L* G2 V8 H4 Z. P2. int a, b, c;- Y1 ^' V% M" C9 q$ A0 W& C
3. public Child(int x, int y) {
5 f" ^2 g; Q" }) z2 }3 f n. r4. a = x; b = y;
+ I* h$ |$ {+ }0 T; C- z5. }9 g8 R* U4 Z$ W Z3 W' p
6. public Child(int x) {
) Y: W$ B% o) {) b) M; X& M7. super(x);
: s3 `3 G3 Y V, N$ T7 w( }8. }
( U: d* F5 B7 t/ O; l9. }& }( w/ F" L/ G4 |1 s% R+ @
为了能使该类编译通过,下面那个构建器必须出现在父类中:1 M$ O Q: n4 ^8 n# |9 ~
A. public Parent(int m,int n). w& j& T' y' [" Z: p
B.public Parent(int m)( t; R/ q1 ]( U
C.public Parent()
, H% m5 @$ v7 ^' ^D. public Parent(int m,int n, int o)# p0 n* K5 s2 ~5 {9 L
8. 读程序:
) W8 _0 C9 q' ?7 @( ]1. public class Derive extends Base{( i3 v3 v0 Z7 d8 L+ c. |% W
2. public static void main(String argv[]){
0 t6 U* ^, F) A0 j3. Derive a = new Derive();( B4 ~3 `( B2 t9 Q" N
4. a.method2();
1 F) |0 K8 @/ b9 t0 f. |5. }
1 E* M/ D9 G4 C8 S6. public void method1(){: _$ Q% N3 f& a9 G; W) f
7. System.out.println("method 1");
5 I% f# _- K$ v8. } % v1 ~- @. _) n7 V
9. public void method2(){2 O5 Y% e$ J h O4 i) J0 \1 ^( A
10. method1();
+ T3 p/ C. T6 c$ F- z7 K11. }. O [: U) b9 F0 a8 i) o
12. }
8 K4 l0 W2 D0 r! Z2 v13. abstract class Base{
: n7 f' x3 E" u8 u' I" o8 E4 u7 p14. abstract public void method1();9 c; y, ~2 E( q- }
15. public void method3(){6 _; M% f8 T4 B. z( j0 W! W1 w
16. System.out.println("method 3");9 M* D& p0 p9 {, E& c6 k8 n7 R
17. }
2 \1 l C6 i1 `! T9 X. T}( E8 C0 R; o9 Y: J- P3 g
当编译和运行该类时,将出现什么:
0 |& H: {/ K* ?. ?4 yA. 程序输出“method 1”& c3 ^2 [8 b, z4 d
B. 程序输出“method 3”2 u0 k, B; H' z6 j( y
C. 程序因为第15行而出现编译错误3 b, H) s# E7 A7 ]0 Q, @: G
D. 程序因为第15行而出现运行错误! h) v2 H5 G" }
9. 以下哪个接口的定义是合法的:% [, q( _! F5 m4 E, Y+ Y/ P
A. public interface A {int a();}
% ~' E4 H6 U+ z" K% m) o9 VB. public interface B implements A {}9 W6 ^, q( P, m: X
C. interface C {int a;}
& l$ d' h% g1 d: P) u4 xD. private interface D {}
' r) r; e% K% A; B* ^: f10. 读程序:
) E$ x4 A, A8 d7 @4 {1. //File SuperClass.java
' K$ w. ~1 T2 _& R# ~& T2. package MyPackage;
- X5 m7 M$ i4 S. ^3. class SuperClass{6 w( K3 f$ \+ G9 Z U( I
4. void myMethod(){6 y4 K1 j' X( ~ X- J
5. System.out.println("SuperClass");
" p! o8 a9 K5 N/ ?1 K1 y6. }9 |* f' C+ I+ |) C
7. }
6 p- L9 D2 ?% M: ?8. //File SubClass.java
8 ]% D9 P, h+ C" b9. public class SubClass extends SuperClass{
2 J1 e8 K8 X; M7 Z2 ?/ N10. public static void main(String[] args) {0 `8 r0 E" \; g* ^
11. myMethod();
( O" S- r! J0 ]; y# g3 ]5 i12. }7 E* l. C( p( g8 c$ ~! ~6 e
13. }0 _6 H. |* ^' _) j( a
当SuperClass.java和SubClass.java在同一个目录下时,如果编译和运行SunClass.java则会出现什么情况:% Z- k" w( i5 t
A. 两个类都可以编译通过,并且SubClass运行时会输出“SuperClass”8 u% k. ^/ F0 U" w1 c
B. 两个类都回出现编译时错误7 K, o, z0 j! a( ]: w- u
C. 两个类都可以编译通过,但SubClass会在运行时出现运行时错误
* v. Z4 A g1 i- l3 u$ lD. SuperClass.java可以编译通过,但SunClass会出现一个编译错误
' L9 C7 |- a1 F2 G( S11. 读程序:
" q+ [' X9 c; |1. public class Test{
! s' \1 n; m1 b3 c/ T) U2. public static void main(String args[]){' B# _! N f2 i4 c' G
3. int[] i = new int[5];$ Q1 M% A: G7 W
4. System.out.println(i[5]);5 Y* c& P1 f) w3 c! A9 ?
5. }2 w7 v! c# `, w& ^$ d* E6 p& j
6. }
9 S+ v5 P9 j* d当编译和运行该类时,会:
7 K" d( x$ Y O# d7 z! F+ ~0 ]. k, O+ OA. 出现编译时错误
4 \' O4 h R* {: A4 N, HB. 出现运行时错误! ?4 q# m5 M7 Y& z4 K1 w
C. 输出0
$ H1 G n& Q$ H3 l4 \) F; tD. 输出null W/ M% V) B$ Y& `# \
12. 以下哪个选项是正确的数组声明或初始化:; |2 N; U* o3 M
A. Array sizes = new Array(4);+ a! K1 y1 H$ C% @( j
B. double [] sizes = {1, 2, 3, 4};$ b) H8 ~. ?: e+ o: M+ u
C. int [4] sizes;
5 I& T: X( E& j# B: zD. long sizes [] = new [4] long;) I2 b/ J* e6 G. O* ~8 |
13. 读程序:& s) ~) `" p( B D2 g
1. public class Initialize{
! u L3 M; x* _! V; c2. int x = 200;# U! r" S7 z/ p# k
3. static {) _+ f# j. H4 r& S- { a
4. int x = 100;0 [5 K% W, V# C$ M4 E; w3 R0 ?* @; r
5. }
5 S0 j8 c( y1 J* b" k, M' }6. public static void main(String[] args){4 Z% @7 ~6 ?1 ]2 T* i* m
7. Initialize init = new Initialize();( f1 T6 ~* L- d6 u
8. System.out.println(init.x);
O3 B( M @( ~+ y6 f9. }" a, V% @; k$ ]% w
10. }6 q' ?% Y# T6 S0 a6 T( D
当编译和运行该类时:' b# ]2 L* H# K% w1 x2 N1 d
A. 程序因为第3行产生一个编译错误
1 w7 K. B+ a& b+ LB. 程序因为第4行产生一个运行时错误6 X6 r0 F: |1 t$ m8 P S
C. 程序输出100
+ J* s- I: Z8 O5 @; U. RD. 程序输出200) [9 d4 V* g# e! i! T
14. 读程序:
& c V/ K1 S3 q4 L3 P8 N' B1. public int abcd( char x) {
% D) B3 ~/ f. W. g0 B8 j2. if ( x <= 'M' ) {
4 P- U1 r. u2 \: q( @) h- u: x3 Z% r3. if ( x == 'D')
% H/ z0 L0 X& n8 O! n4. return 2;
3 c' L2 p" Q) |0 r! A5. return 1;
- r& ~. u1 Z/ c# `9 z- x) n6. }
; b# L* g/ E# K# a% j) ]7. else if( x == 'S') return 3;
; c' [7 ]# R+ y, C4 y M" B/ A8. else if( x == 'U') return 4;
1 t7 \3 x, h6 G3 m" W9. return 0;
: j! T. c3 l- y4 p6 _10. }7 g$ J: [% J$ b1 H5 B) H# @8 {
在调用abcd(char x)函数时,下面哪个选项作为参数时,会返回1
$ K/ x) X% j) i8 L9 @1 U& l! fA.‘X’4 K& C( |. o$ p p( [4 q
B. ‘A’
" d( ~0 ~( i: v4 G% [5 v0 e* |C.‘D’
, W7 b% R7 V7 a- r+ pD.‘Z’
/ ?5 L9 A0 L! c; |5 d15. 读程序:
M9 o1 N2 x" H$ ^1. class TryTest {
8 Z, u. J+ F2 V9 K+ W2. public static void main(String[] args) {
5 U6 A; c: N$ S0 M; E0 R* k9 X3 \3. try{
( A5 w, L/ w3 @" _5 Y4. System.exit(0);
+ X _- U+ {" \- j! b4 P" {5. }3 {- x" |) \ |0 O% D! X
6. finally {
& ?9 a5 c( F, `, a7. System.out.println("Finally");" i: R* k5 ]3 O9 B, J, x2 b
8. }
( ]7 Y0 R5 Y; I1 t- i1 u. J9. }
z+ ?/ C' N* r2 r9 T10. }
5 g& v5 G& K2 { e2 Y( l: C当编译和运行该类时,将:
, o! a; r; `6 KA.程序因为第4行出现编译错误
* Q" Z n& N4 p: P# O5 `B.程序因为第4行出现运行时错误' Z1 G- z9 K+ a7 U" l
C.程序因为第6行出现编译错误/ \# E! b4 i8 d) i. s
D.程序因为第6行出现运行时错误% o( L4 s* T+ N& ^. w+ o
E.程序输出“Finally”
) Q. b. Q1 t) U$ A" t$ M8 cF.程序可以运行,但什么也不打印
. F: D. |4 A4 s1 x! g, l
' z$ r3 a7 D) D* k R16. Given the following variable declarations:
9 N8 P. K$ B% Q: [# i- o$ wBoolean b1 = new Boolean(true);
% M2 s+ w& ?, M0 n( m( @Boolean b2 = new Boolean(true);
* {$ d; E5 q5 [9 V- HWhich expression is a legal Java expression that returns true? 6 l' a) F3 B$ ]) \
A. b1==b2, }3 _) @ y0 _ ]- I3 J! g# n
B. b1.equals(b2)
* L+ u" W2 }0 ?0 |3 XC. b1&&b2
: z! L2 X" j$ n) h: m1 j# aD. b1||b2) C& S; b+ w0 L. L$ f* V F/ n
E. b1&b2
1 D7 l5 `! g3 pF. b1|b2
9 d. A) F1 _$ b* O17. Given: 2 w, O6 u4 I8 L2 w# R$ H
1. public class Employee {
; J$ e: B' F1 A) @* {0 E2.
" v1 v2 \! o$ C: l3. }$ E6 S. I0 K! m5 \4 R
4. 6 P# H9 H! ~( |7 r+ q4 p
5. class Manager extends Employee{
- }2 d5 k1 Q K! A+ v! K+ ~6. }
; W( M9 ~- b! R& PWhat is the relationship between Employee and the Manager?$ h o8 l9 q# \- T0 s$ K- W/ ~
A. has a
% B3 b" H7 s$ W! tB. is a
2 O5 x+ d( E- K; m; _5 \% A, R; aC. both has a and is a: d# y6 V: ?) |! Q. g
D. neither has a nor is a: u* h7 D+ h; v4 b# t* x
18. Which layout manager arranges components from left to right, then top to bottom, centering each row as it moves to the next?5 U# ~0 z( L1 b. D1 f& g- W' n
A. BorderLayout2 S) W, Q0 E0 T% p
B. FlowLayout6 u2 h9 D: ?( v0 c9 W, E: `* v2 k* ~
C. CardLayout( {5 |" }) K" s* `
D. GridLayout* ?4 B# p0 p# }( x/ c
19. Which of the following AWT components can generate an ActionEvent?' E: H1 q) G2 d! v ^
A. java.awt.Button/ \3 G1 ? `2 g& d
B. java.awt.Panel
u7 V1 ] R. q; Q/ j3 AC. java.awt.Canvas+ N, ~1 n2 Q& g# d7 H$ y7 ?# H
D. java.awt.Scrollbar
1 }* D$ y$ I& Z! L) c7 k) y4 `20. What kind of Stream is the System.out object?
' r2 t$ G3 a9 T% C: ?7 l1 ~A. java.io.PrintStream2 D j- I; e8 V
B. java.io.TerminalStream
) M- @5 l4 `- j7 D+ @+ t3 B2 o/ t. l0 xC. java.io.FileWriter
* O" l7 Q6 a" m. P7 z# M7 cD. java.io.FileWriter
% N8 c+ Y* X6 Q/ Y0 o1 a+ s, i21. Which of the following events has a matching adapter class that implements the appropriate listener interface?(双选)
' V( m1 b$ p7 Z+ ?! j3 w. JA. java.awt.event.FocusEvent; [- p3 \& r1 A- c$ z
B. java.awt.event.KeyEvent
( y9 e3 b: l! I! M) h4 hC. java.awt.event.ItemEvent
/ p1 b* p" y' H, Q( }. R7 K: FD. java.awt.event.ActionEvent( Y; H6 O1 a, Q3 U- Y8 s
22. Which of the following methods are static methods of the Thread class?(双选)
/ H* u# v1 k/ S& o BA. sleep(ling time)
/ M. N9 F N+ r8 I* [" ?B. yield()
: B# [9 Q; }* a4 j9 MC. wait()
" z m8 }! d; D1 ]+ tD. notify()1 l5 q1 u4 t/ p9 q3 |) ?/ D
23. Which method do you have to define if you implement the Runnable interface?: @4 n! \' c { i3 u D
A. run()0 J8 ]3 B2 z8 ?$ C& x
B. runnable() ?" E$ m8 W7 d5 W" |2 {7 a2 h( l
C. start()
. m5 Y/ J+ A8 L' k: C% [D. init()7 x* r) {3 b. F' F9 w/ @- o. v
E. main()0 H% c* ~% f3 p% B: W& D+ }1 t
24. Given:3 Y: A) p# w7 S3 k% }" K
1. class MyThread extends Thread {) M1 N7 p# x- L. Q: K- t% H5 `$ ?
2. 7 A" v1 ?8 ?2 |3 i$ ]
3. public static void main(String [] args) {
; l& L, E' w" _4 o, s5 X4. MyThread t = new MyThread();
& r8 y& ?2 S' t" G5. t.run();
% j( h; i! Q4 v; V N. C6. }- e& T# T+ a. d1 |: e8 T& @
7. 6 a6 n% B6 I+ c, B3 y. m
8. public void run() {
; h) B! j6 m1 e! c& R: t$ ?! W `9. for(int i=1 ; i<3 ; ++i) {4 d, E: B1 K; V$ I9 [$ y
10. System.out.print(i + "..");
5 n. \# {( h. a& y5 _' E- @( }11. }( J: s5 G$ m Y4 F2 s3 B
12. }
* g# t% W, `! p. k& A3 I13. }
6 Z) G2 t7 C- @! q, l8 vWhat is the result of this code?C
& b+ I% l1 n( ?( e4 qA. This code will not compile due to line 4
{2 k( P n8 ?% A4 M; ZB. This code will not compile due to line 53 g+ L8 ^2 o" ~
C. 1..2..
4 A! v8 X: g% n* i' O! |) iD. 1..2..3.. i( U8 t4 R- {' X4 U1 D
25. Given a local inner class defined inside a method code block, which of the following statements is correct?
+ h4 P0 D# S, ~: t& ?& v M6 o; i! h3 lA. Any variables declared locally within the method can be accessed by the inner class
7 e! I, \" n1 o+ {. B8 FB. Only static variables in the enclosing class can be accessed by the inner class7 Y2 h2 o4 x" ^! Q9 _
C. Only local variables declared final can be accessed by the inner class
% l' E+ P& t; H+ [* w7 M+ T* RD. Only static variables declared locally can be accessed by the inner class.
/ B+ M1 E5 S% |3 B
9 U$ t. z. m! t! K" g H9 Y# f. t) ?# M7 k$ n( U3 {
6 N- M2 b' ^, i1 h J
26.public class SychTest{ : q6 Y$ q: e& G1 ]6 u
private int x; 7 N( J; B& w* x' ]" ?: q
private int y; - `' O' A) g/ W1 O$ F ^ A
public void setX(int i){ x=i;}
9 y7 g6 {% \& _( `# ~7 ]7 E8 O public void setY(int i){y=i;}
$ A+ Y0 O1 }0 [; ~. _ public Synchronized void setXY(int i){
! m" x$ l2 J* B+ M) U( d1 N setX(i); ) k, {& O5 M J8 Z
setY(i);
+ i7 _+ x' h( T4 J6 W i5 j }
/ I8 Z1 h; f! E! c* t public Synchronized boolean check(){
& e4 p; N3 S& }- A) k return x!=y; 8 E5 g( E% B" T8 H' Z
} 8 w; L8 c+ _& } U$ F' f# A
}
5 C: g9 h8 v/ v- m( D- I: } Under which conditions will check() return true when called from a different class?
5 F, n: I' R6 G: }* S5 r" a- f; f A.check() can never return true.
' }- Y# Q" u( P" r0 N9 X3 A4 p3 F B.check() can return true when setXY is callled by multiple threads. 1 |3 Y* h% t* |
C.check() can return true when multiple threads call setX and setY separately. ' _+ W) {5 u$ ?- C/ |4 Y
D.check() can only return true if SychTest is changed allow x and y to be set separately.
+ A$ O# S! a0 q4 d0 r7 A/ ?
8 z7 C) c" b* L7 W27. 1)public class X implements Runnable{
( W$ K& b( Z7 q! S9 d 2)private int x; : b( n' t$ v6 E9 N1 P
3)private int y; - W" ]. i8 n$ i5 |% ?% ]; `
4)public static void main(String[] args){ 0 F8 n9 t# f! m0 ^+ v9 K& C1 F9 m
5) X that =new X(); $ V6 H/ a* ]: r* |' b
6) (new Thread(that)).start(); / [! F- M% _& l- s& p6 I9 W4 D+ V
7) (new Thread(that)).start();
* V$ [) n3 @1 j0 v1 Q } * ]8 @, g5 i. m& O3 `; Z. s
9) public synchronized void run(){
) u5 j$ H# f' C( h 10) for(;;){
5 f0 V. c3 M+ }. s 11) x++; 8 U. F* P1 p6 _
12) Y++; l9 i: U; A' q4 G1 O7 Z! B
13) System.out.println("x="+x+",y="+y);
3 ?( b! s2 j5 E; p- {: M k" e 14) }
' |. `4 }7 J# B8 u: Q 15) } 6 y4 u- P1 |7 H0 _, O
16) } K6 e; k0 p7 n; j7 B2 Q
what is the result?
# f! @4 F% e4 x7 D9 X- Y4 U: @- b A.compile error at line 6
" _/ \ \( P `; U% D B.the program prints pairs of values for x and y that are
+ ^/ ]) S% K# S- \4 v always the same on the same time
. g0 A9 @' O+ }# F* R: m5 |* J% J
4 V/ L4 Z8 N7 } D28.class A implements Runnable{
8 P C/ Y( t. ] int i; ) ?9 \) D' s' E9 i: C; E
public void run(){ 6 L' {) c+ x; E3 C/ O$ Z
try{
8 G* ~/ D! k* [. l- M Thread.sleep(5000); 0 j1 k3 a( j# _4 j% H' ^4 {: p
i=10;
3 c1 B/ u. _7 F- |- ~9 b" {9 T, i }catch(InterruptException e){}
) r. Q! E9 {$ m8 }6 V3 v- ~3 k } / V/ D6 H3 d6 F& n* `6 ~
} : U7 }2 _0 d: L; Y
public static void main(String[] args){ ( S2 j/ V* E+ W, _" w9 P' a
try{ 5 s/ K( V5 B$ S1 v+ q3 C
A a=new A();
3 F0 u+ f6 C+ v! {6 `4 Y7 S Thread t=new Thread(a); 3 A: s5 a8 d5 T p8 ~
t.start(); % M7 K$ K( h. ~) V) e
17)
" p0 S7 p# a2 G4 _& O int j=a.i;
% O! V, m; B1 m2 k9 `) B) W 19) 1 P6 X0 s$ J, ]$ E6 f- c
}catch(Exception e){} 5 A3 j/ T6 A* _: N
}
7 v& S( \# N v/ o2 R$ U2 x! T+ U } * J( K* {: ^& Z0 R
what be added at line line 17, ensure j=10 at line 19?
) @2 `# b3 _7 |- ^/ B- _$ K A. a.wait(); B. t.wait(); C. t.join(); D.t.yield();
1 K9 P; g0 x4 G G1 w$ C E.t.notify(); F. a.notify(); G.t.interrupt();
" a8 a# `1 M B% ?29.1)public class X{ / z' |5 V# j) ^2 w& c/ q
2) public static void main(String[] args){ ; u* k8 @( t. {/ T* a* R
3) String foo="ABCDE";
# ?. b; x- l8 _ 4) foo.substring(3); 7 C% s- }0 r% ^* j* s- }
5) foo.concat("XYZ");
) I- K( ]+ @4 [" H2 X/ J 6) }
$ h' ^' r( n2 ^2 a 7) }
, `4 U- r- A. a7 H what is the value of foo at line 6?
) h5 C! C# P4 T, Q* V30. public class Test{
7 b9 {$ |4 @7 ^% R- O# y, }9 {. W7 S public static void main(String[] args){
% M! Y. H* I3 |6 J0 R1 X% E, g0 ] StringBuffer a=new StringBuffer("A"); 6 a$ [. R' B% P
StringBuffer b=new StringBuffer("B"); ( t1 ]$ ^" f& ^ p
operate(a,b);
; w- p1 C! u U3 b1 ` System.out.pintln(a+","+b);
; s: R% L) { A5 n) s2 a$ K } 7 T/ x9 Y0 h, N& ]9 p
public static void operate(StringBuffer x, StringBuffer y){ ( F' X/ s& W H* b" ~" A% J6 z
x.append(y);
. ]1 S' |& {7 ^9 k- z+ @* J% r y=x;
) J3 d* s) l1 r) n/ X; a7 i3 ` } ) R5 m/ q% p K6 E
}
* V4 R: r% _' T6 w8 |$ h/ F; w+ g what is the output? |