a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 106|回复: 0

[考试试题] JAVA认证:SCJP考试真题和剖析

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
例题1:
( e- |$ v/ q/ s/ a& G9 T' `Choose the three valid identifiers from those listed below. 4 v5 Z- V/ T; F/ n' S  Z! {- M
A. IDoLikeTheLongNameClass
  w+ s$ F& u$ \/ t+ h. r* N+ {, UB. $byte " C% h7 ~$ D7 t) u( d
C. const
1 r8 i0 [6 g7 Y3 m  v% HD. _ok
: v& w9 ?$ n% L( wE. 3_case ' e, P* d# o4 f( E6 A2 y% Q7 b
解答:A, B, D ' i1 H/ e3 v5 O
点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头。关键字与保留字不能作为标示符。选项C中的const是Java的保留字,所以不能作标示符。选项E中的3_case以数字开头,违反了Java的规则。
0 W* |: @; T9 I( ~$ v+ u例题2:
$ v- j( B/ f! f+ a# y4 NHow can you force garbage collection of an object? . x6 U5 f! P3 M. ~
A. Garbage collection cannot be forced 6 g$ o( O/ ?2 }; {& }8 u
B. Call System.gc(). 1 a$ s! G- n4 T3 }# Z: B& t
C. Call System.gc(), passing in a reference to the object to be garbage collected.
% T/ y" s1 ^9 u, F4 UD. Call Runtime.gc(). 3 m' s) V0 g! `3 {, S
E. Set all references to the object to new values(null, for example).
- s2 p' E6 ^$ M$ n6 }: f' ^解答:A
) A, H# O7 i/ w5 F点评:在Java中垃圾收集是不能被强迫立即执行的。调用System.gc()或Runtime.gc()静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。所以选项B、D不正确。选项C的错误在于,System.gc()方法是不接受参数的。选项E中的方法可以使对象在下次垃圾收集器运行时被收集。 : G2 m4 W: M0 t- D; |( F* S/ E+ f
例题3: 5 j/ V) ], A! K5 V
Consider the following class: 5 B" M' _8 J, F; b6 }# Z% w
1. class Test(int i) { * ~* H0 w$ E+ w8 x
2. void test(int i) { 9 d! z- F! Z+ H4 W4 a$ \
3. System.out.println(“I am an int.”); 7 ^) y% I6 ?( e5 X1 m
4. }   q& _1 @" J# v$ {* W
5. void test(String s) { # [0 M8 h2 N" \& q5 m; ?! K- N3 Z
6. System.out.println(“I am a string.”); 8 I  M; k% d$ g! n; f. e8 t
7. }
. M, J4 h7 U0 h. X- }8.
8 p' {" t: D6 `$ ^! I2 @/ }6 s* B9. public static void main(String args) { $ ]1 N* t: f3 y% M1 V
10. Test t=new Test(); 2 \* }$ {7 F3 g: W; Z# _7 b
11. char ch=“y”;
( v2 b/ ^3 `, N+ P+ O12. t.test(ch); 1 h: E1 ~- L9 t4 q
13. }
" h1 T0 w6 R& S% t7 v1 z' R& k14. } ' Y6 D; R" ?+ R! A
Which of the statements below is true?(Choose one.)
& D; f: d, _: z0 g9 ?A. Line 5 will not compile, because void methods cannot be overridden.
: |% N# j- }& L( ?' IB. Line 12 will not compile, because there is no version of test() that rakes a char argument. - w; N' b  ?/ x! c: u% v# V
C. The code will compile but will throw an exception at line 12.
0 m3 M' K$ s4 d! M; n& mD. The code will compile and produce the following output: I am an int. $ c4 Q& b, o* m. \) y
E. The code will compile and produce the following output: I am a String.
6 B0 b: w9 U0 O7 w8 v# E+ L2 M解答:D 点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-15 19:32 , Processed in 0.661592 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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