a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 143|回复: 1

[考试试题] 2011年JAVA认证模拟题第二阶段(18)

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
  Q52.What does the following program do when it is run with the following command?java Mystery Mighty Mouse, _5 B6 F# D- |( @) r
  1. class Mystery {
2 e6 @3 j: I0 F  2. public static void main(String args[]) {
, X& y: P# L8 [( Q! Q5 f  3. Changer c = new Changer();
; M; o5 k2 C4 P7 t+ z, p  4. c.method(args);
. M( M  P4 o  U  z+ J/ X2 Q  5. System.out.println(args[0] + “ “ + args[1]);/ p) n. X( C, c1 j- c0 N
  6. }
; B: ?. F% U: m9 F5 l  7. static class Changer {
$ C. l$ s/ i5 A' r4 ?! ^* N& y  8. void method(String s[]) {# U" k( g9 f3 n# y1 X: d
  9. String temp = s[0];. d. ~5 I/ g  Z; D2 t2 F
  10. s[0] = s[1];& g! H9 u( [5 y; q0 G# m- u+ f
  11. s[1] = temp;
) X$ a7 L6 a8 x  12. }* c0 }8 ^- @2 v
  13. }
) I; J3 F' T0 h" g  14. }
8 t  x$ W$ e* m! d+ T6 `, @  a. The program causes and ArrayIndexOutOfBoundsException to be thrown.3 S: B/ {, h/ B+ T
  b. The program runs but does not write anything to the standard output.
2 |/ O( S6 V% b" q/ G$ k  c. The program writes “Mighty Mouse” to the standard output.7 L; t# i' I, y, N9 `0 N
  d. The program writes “Mouse Mighty” to the standard output.: U1 W; |5 V8 v9 ~
  Q53.What happens when you try to compile and run the following program?
5 A% w5 X$ t0 c; N$ x" C7 z  1. class Mystery {
7 u2 J9 i1 ~  X4 u: G3 k  X  2. String s;7 M# `; b# Q. }! u$ I5 }: Z" {4 i
  3. public static void main(String args[]) {: Z/ e1 Z9 b( u  M, q' f5 k. G
  4. Mystery m = new Mystery();
4 K+ E( A) h" E, E: ~8 ~4 X/ W4 e  5. m.go();
! U9 M4 f7 i. }7 w$ k  6. }
0 N2 `4 O/ Y' V" ~# F; W  7. void Mystery() {" w( G; I- t- ]- W* j5 R
  8. s = “Constructor”;
# ~$ F, Z* y# f
+ ]! E% c; X2 Y7 A$ b  9. }
回复

使用道具 举报

 楼主| 发表于 2012-8-4 12:33:17 | 显示全部楼层

2011年JAVA认证模拟题第二阶段(18)

</p>  10. void go() {
) z9 f$ B, n: e+ d: g3 [3 I  11. System.out.println(s);. v, \, p! W7 x3 Q: P  [/ P3 V" y* Y
  12. }9 g0 o, d6 \: M' @
  13. }
' }$ k) M6 z3 S( h  f5 y  a. The code compiles and throws an exception at run time.( A# W7 {# C& T1 u
  b. The code runs, but nothing appears in the standard output.
0 U7 ]+ V$ S' C3 d  c. The code runs, and “constructor” appears in the standard output./ P8 f' q8 i$ ^$ k% M$ F8 d8 f
  d. The code runs and writes “null” in the standard output.
+ I' ?, c( B% u: c: W/ J/ s  Q54.What can you write at the comment //A in the following code so that this program writes the word “running” to the standard output?, t0 ?: o4 z# `
  1. class RunTest implements Runnable {- i2 i' j4 h  Y) s/ \8 Y5 u
  2. public static void main(String args[]) {
3 r: o7 e; M6 w1 f  3. RunTest rt = new RunTest();; [6 B" H- G% q, z7 }/ f- Y
  4. Thread t = new Thread(rt);
# l) E5 s- V. o  5. //A1 Z6 ^6 q$ @# B! H* Q, S+ W6 N
  6. }
) O4 k! Q. c, ~+ ^" u4 @! v  7. public void run() {
3 g  _" J6 `3 W  i  8. System.out.println(“running”);
7 v, d2 t7 Y+ p' b: T# S  9. }
: W9 G8 T, o0 _3 M( K  10. void go() {
! h: f3 q& w0 n( a2 C  11. start(1);
$ Z& c2 Y8 g9 _6 y7 g  12. }
% P' \# s' R) B. D  13. void start(int i) {. {1 @# D( T# n- K; H1 H) P* [2 m4 z
  14. }- S6 y- O& I: X# O6 Z
  15. }
  y2 P1 e6 Q0 m, v  Select all valid answers.
( R3 a# o. I+ q* I5 b, ^% ?  a. System.out.println(“running”);
$ u1 h& d" S, L5 v* ]) C- v  }4 v  b. t.start();
2 h9 b1 C" k' f5 I% ?  c. rt.start();* U- b8 e% L5 R- |
  d. rt.start(1);2 U# u. Q' Z- o8 ^3 ]/ \7 P
  52. d; P# L' s  a1 E+ a) x% q* A
  53. d' W: O3 n+ A: ]6 Q
  54. ab
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-21 18:55 , Processed in 0.209403 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表