a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 99|回复: 1

[考试试题] JAVA认证历年真题:310-025精选题(49)

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
310-025精选题(49)的具体内容如下:* Y7 f# p/ k- }, |9 k; {$ B# j# s1 s; R3 g
224. Consider the following code: What will be printed?
1 S/ H, i! E/ ~; W- ~& a% qpublic class Q{# h8 @5 z; K2 O$ y: N0 }+ Q/ d+ j
public static void main(String arg[]){
5 T; N& I  |. X! ~/ B/ p- }9 u3 u# kint anar[] = new int[]{1,2,3};2 g4 h6 q0 F# D1 o
System.out.println(anar[1]);
- W6 R, z& x; D% h+ F" hint i = 9;* T3 ^7 h+ e) W1 M6 ?
switch(i){
3 O& w5 Y) z5 R7 p5 \& |6 pdefault:System.out.println("default");
& `2 ]; [0 ~/ m/ q8 ocase 0:System.out.println("zero");break;1 ~4 D  G2 R% U( m* g: W( ~: i1 M
case 1:System.out.println("one");
& M( \8 i' ^6 n& ncase 2:System.out.println("two");# I- b$ s" D- l7 B( A8 M
}
8 e4 \! R: B) @' A, iboolean b=true;
6 i9 L$ Z( G& R7 q, k, n: r' D7 Mboolean b2 = true;; M1 C4 V( q- t1 m
if (b==b2){  _  x" q+ h+ p1 G4 z+ F
System.out.println("So true");2 Y  Y. q0 s3 u3 H3 O8 g
}' r6 h1 Q) E5 y, a, `  y% Q- R) {' P
}
3 C3 {5 k4 Y+ |7 h; x}
  y( }1 a: G0 RA. 2 default so true
/ O7 v% N. r0 ]$ }: PB. 2 default zero so true
1 [) p$ [" ^, h1 l" l% A+ _" LC. 1 default zero so true
/ c; V. [# \0 y& [D. 0 default so true
. \& s# ~5 k* BE. 2 default zero two8 R' ]) F: G. J
F. 2 default zero two so true4 c7 P: ~7 j, [: |
B.# i8 |, x: G% k) Z
225. Consider the following code: What will be printed?
0 E; q1 \. @% O4 Dpublic class Scope{
# p; J5 R+ g' \5 v  u" aprivate int i;* w! ~- Q9 G# B! j
public static void main(String arg[]){
7 e3 H1 D3 U) P% o0 I4 zScope s = new Scope();
% @6 x* G6 k/ K4 u$ Ys.amethod();2 I% C. g- e! b) S" L1 a
}/ x8 E( T: C( E
public static void amethod(){
7 T8 h  U, T3 j0 `6 F) H9 |2 V* jSystem.out.println(i);1 l/ o, n: R3 j: W/ [8 s  _' i
}
; L, o, F6 l" }7 H# ?9 K}( O% u7 \4 `+ T1 ?% |
A. 01 }/ \/ _; n! J, {
B. null2 U6 i2 m0 l8 c  @
C. Error. Non-static variable i cannot be referenced from a static context.. M6 \# u* p- [' P: V5 {
D. Error. Variable i may not have been initialized.+ c7 L5 P/ D" I* \( f
C.
回复

使用道具 举报

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

JAVA认证历年真题:310-025精选题(49)

225b. Consider the following code: What will be printed?) I& a6 S; Y7 D9 J
public class Scope{
) m* P& I- i& \private int i;) Z; x+ ^% T* j  `8 l
public static void main(String arg[]){
8 `8 k; [2 Q, e* V5 [( HScope s = new Scope();
) r# n% U) Y. s( x7 ^- Es.amethod();
4 r* h1 \$ U3 e/ i- E}
. c: M" U3 L! V+ H# Y5 w2 ppublic void amethod(){
# X8 z& T0 A1 r+ ^+ MSystem.out.println(i);1 g7 E& G) n2 v+ @6 Y$ H
}
7 ~  B' {9 h. o. v}/ ?+ @2 K5 F* p) Z4 Z  r. P0 }2 P
A. 0
, r& Y* w# T9 n% p/ y3 v, l4 QB. null
  C3 L) l0 o0 ?( Y& R- TC. Error. Non-static variable i cannot be referenced from a static context.6 O& n5 H: Z' N& L$ p
D. Error. Variable i may not have been initialized.
0 [* }/ [9 l' J9 C. aA. (check)
0 a' b' T, }% z5 }, C226. Consider the following code: What will be printed?
4 P: w/ D5 F' L- h6 upublic class StringBuf{
% k- _5 |9 K4 p2 H6 x- ]% N' m1 Dpublic static void main(String args[]){
0 C" z5 S8 y; d6 V2 q+ A( d1 H% fStringBuffer sb = new StringBuffer("abc ");
+ L' i* g. y0 ~2 E% j6 k7 YString s = new String(" a b c");
7 I4 h* D& ]  r, N1 IString st = "ABCDE";% q: u6 W. w( M; b9 E
sb.append("def ");//nu är s = abc def
2 j$ Q3 G* _! X# jsb.insert(1, " zzz ");//nu är s = a zzz bc def
3 l: \0 j! I4 B- r  e9 _6 @String i = s.concat(st);
3 k! E# C6 z: P5 {8 s3 w5 e; Ds = s.trim();
0 x2 X0 r7 j+ |/ P: b0 W+ ySystem.out.println(s);& i$ v0 h( p3 W7 I
System.out.println(sb);" a6 Z/ Y  W! ^; C+ X4 {) {
System.out.println(st.indexOf("C"));, p" J8 r* e0 d& M
System.out.println(st.indexOf('A'));
9 [) R3 Q! ~' S5 m; w. LSystem.out.println(st.indexOf('A', 2));
# d/ x$ K3 Z9 {: q7 K3 F" ~( FSystem.out.println(st.indexOf('G'));
% _' N5 ?. L2 ^! i; Q8 N, Q- _+ rSystem.out.println(i);- w+ b+ p& g+ [' P1 I) T
}
% P/ n; G6 U: G! s) x. s9 h6 Z}
* f( x7 y; e( b* W2 z+ ~0 y3 @- s7 _What will be printed?
1 T! A2 f3 P; R7 m, W! u- o* }A.) Z; T3 ], l1 o4 d: C# \- N  I0 r( g
abc6 u( ~2 m0 M" t2 w
azzz bc def- Z6 q2 d: ?( w( _0 `& x# ]0 v
2
' I9 h. L$ Q4 d2 {- J06 M9 Z' K" g) J; N
-1
2 V5 U) c6 m( c' n-1
: A8 e* z8 `6 Y* x5 r3 D4 Ka b cABCDE
3 k8 g! J+ F0 P' x( d( |) w$ @B.
; g' G5 u. Z; m- o: Ma b c# d/ a  \" }" c6 y8 \7 h: F5 @
abc def zzz' {0 f: X# n% ~* P6 ]
2" J  X" w" y  Q
00 b( |, z* l( V5 v6 U, j6 k
-1' W! H" j9 x: w: m' N% u$ n- E- h
-17 Q/ n0 V: z; ~" P' u
a b c ABCDE
; j9 O/ Q7 b8 L$ o# X% EC.
4 L# F6 V6 o, A6 O" _* E3 G4 H$ vabc) b6 e6 c, X5 x2 j6 n6 ~/ L
abcdefzzz
  Z' l1 f7 L% r: j. e8 G/ l2
* A  m- Y: a0 {( R, N' i( L3 ~0
, b3 X1 B$ I2 u5 o( z% j8 L1
) ^: ^% A& `/ O$ U# d5 H-1' M5 M# G% P6 q  A
a b c ABCDE) ?* y  a' p/ a
D.9 B& @  t/ |' x4 d% O
a b c
3 b" c! n; V5 Z* v% L( M) I0 za zzz bc def
) n# W6 u' m' r$ R: c2
' P$ I7 e5 w, [02 r( a% q4 [" }: ?: V
-1
, |# f! D5 E) M5 P6 H-1% s6 P! C$ k4 f5 h/ ~. z7 J
a b cABCDE1 h/ K- E) f0 f6 V
D.
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-19 05:27 , Processed in 0.568544 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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