a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 96|回复: 1

[考试试题] Java认证模拟题及分析(4)

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
question 45
2 B+ M: z9 Y( F3 }& F, ^3 E( ?what will happen when you try compiling and running this code?
* }& H1 O( `. n4 C- |5 V: D3 L/ E- Zpublic class ref{ 5 r* ~1 x' e& J# g
public static void main(string argv[]){
# M; c% B+ w8 |! {; v4 t, L+ mref r = new ref();
1 c( N# p+ r+ k& f$ {. dr.amethod(r);
) T5 Q( c7 f1 q}
; p9 ^5 t: I; s: g4 O$ K( N; Upublic void amethod(ref r){ * g& ^4 Z* X" u$ W( x' F
int i=99; * |, ]& O2 f/ s3 b, R1 U
multi(r); 2 r! g9 E) G4 W8 k; ^, y
system.out.println(i);
$ g: [  B: g! m  G. V1 T} " B: n: ?( c& B. @, ]
public void multi(ref r){
6 p3 r% s1 _8 Q0 y$ Nr.i = r.i*2;
+ B7 i6 k) F$ i0 f8 B}
9 m* o+ a1 j  F) Z- I$ F' U" z} : K( r7 c  i4 Q; m  x" R
1) error at compile time
" }  U# W% ^6 A8 P2) an output of 99 * n+ i! Y( W5 Q. ]* ]2 z
3) an output of 198
$ ?$ s4 j: s/ X6 s5 |% A4) an error at runtime
! ]& R9 n! @' R) x3 k# ~" I  M2 \5 y6 F3 \answer to question 45
1 J- e  P+ H3 b8 o' {! ?5 {-------------------------------------------------------------------------------- 8 R: C7 V# z4 [; u9 p
question 46) ( u5 s5 {$ X6 g1 h7 J
you need to create a class that will store unique object elements. you do not need to sort these elements but they must be unique. ! f5 H0 ]% M8 _) |3 P0 o
what interface might be most suitable to meet this need?
3 W2 W+ k; L& t, M8 r1)set # `1 o1 O; N8 \
2)list
4 s) W, T( B! Z* }+ g1 p: n3 [3)map ( a0 A! R$ F- Q
4)vector
# P7 v+ I6 O# ?! w. I" _& ]# @' m* ?answer to question 46
. g# |5 c/ y% d6 x0 T! k--------------------------------------------------------------------------------
6 y. ]$ S  x, H9 `- W! J: f. iquestion 47) * O3 ~5 e/ o$ X. {' m0 ]8 G  u
which of the following will successfully create an instance of the vector class and add an element? ! U' K4 a) s9 ~' R  x
1) vector v=new vector(99); ! h: I& q4 m; n5 K# j
v[1]=99; 2 J( ?- Q  X/ i. J) W, k' _: Q/ a
2) vector v=new vector();
: H1 ~' q7 |/ J' Jv.addelement(99);
% `1 s+ u# T: s- }
+ b$ [( }) {/ }& h& m5 ^( C3) vector v=new vector();
回复

使用道具 举报

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

Java认证模拟题及分析(4)

v.add(99); </p>4 vector v=new vector(100);
5 I) V( S) h' sv.addelement('99');
; a, p' S; v& k/ V5 Lanswer to question 47 - h, f! S: w1 W2 d
-------------------------------------------------------------------------------- & o) j& t0 w+ a3 u  G
question 48)
- e+ H' \& k2 l+ c8 W' R9 p5 Kyou have created a simple frame and overridden the paint method as follows : o, x2 Q) m4 a6 h1 U
public void paint(graphics g){ % r9 u& d+ _3 w& n
g.drawstring('dolly',50,10);
+ s6 d3 k# t; X' W2 [6 ?) C7 T} . G& L9 X' L8 c9 j7 T5 i# i
what will be the result when you attempt to compile and run the program? $ U- V) B4 w0 C) p
1) the string 'dolly' will be displayed at the centre of the frame
0 `; e' t) ?- j2 h, U/ O2) an error at compilation complaining at the signature of the paint method * U7 K( N2 x) y4 ?- P
3) the lower part of the word dolly will be seen at the top of the frame, with the top hidden. . R5 E3 t4 Q1 S  o
4) the string 'dolly' will be shown at the bottom of the frame.
9 g2 k) q3 D) O) g9 Aanswer to question 48 & v9 m: c! u: o" Q4 s& l" ~
--------------------------------------------------------------------------------
; ?" J: H7 l1 ~8 \4 I! Cquestion 49)
% V: c; a! q; e5 fwhat will be the result when you attempt to compile this program?
7 C1 ]2 r, `( _( M6 K4 bpublic class rand{ / K" b% }$ K  a, S$ v, ?
public static void main(string argv[]){
; o: A! H( J4 N8 B/ z0 @int irand;
+ e/ \% B1 j+ U. Iirand = math.random();
: J1 y6 Z3 s2 ^1 f/ i  C* |! |- Asystem.out.println(irand); % F1 c8 ]9 |# j- ~+ t
}
" _4 {: T: \  |) j} 3 }$ Y4 Z( b- B" O3 N2 i* c
1) compile time error referring to a cast problem   V' h( h0 _6 X) n* k( u8 r3 e
2) a random number between 1 and 10
+ ]6 S+ w) T! V3 [- p9 j3) a random number between 0 and 1 & b. P; E/ g$ U0 a- E" ]* S, b
4) a compile time error about random being an unrecognised method
, l2 E$ J' ]. v- canswer to question 49
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-26 00:15 , Processed in 0.371084 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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