欢迎来到天天文库
浏览记录
ID:34840814
大小:72.50 KB
页数:15页
时间:2019-03-12
《道scjp测验考试真题精解》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、35道SCJP考试真题精解例题1: Choosethethreevalididentifiersfromthoselistedbelow.矚慫润厲钐瘗睞枥庑赖。 A.IDoLikeTheLongNameClass B.$byte C.const D._ok E.3_case 解答:A,B,D 点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头.关键字与保留字不能作为标示符.选项C中的const是Java的保留字,所以不能作标示符.选项E中的3_case以数字开头,违反了Java的规则.聞創沟燴鐺險爱氇谴净。
2、 例题2: Howcanyouforcegarbagecollectionofanobject? A.Garbagecollectioncannotbeforced B.CallSystem.gc(). C.CallSystem.gc(),passinginareferencetotheobjecttobegarbagecollected.残骛楼諍锩瀨濟溆塹籟。 D.CallRuntime.gc().E.Setallreferencestotheobjecttonewvalues(null,forexample).酽锕极額閉镇桧猪
3、訣锥。 解答:A 点评:在Java中垃圾收集是不能被强迫立即执行的.调用System.gc()或Runtime.gc()静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程.所以选项B、D不正确.选项C的错误在于,System.gc()方法是不接受参数的.选项E中的方法可以使对象在下次垃圾收集器运行时被收集.彈贸摄尔霁毙攬砖卤庑。 例题3:以下是引用片段: Consider the following class: 1. class Test(int i) { 2. void test(int i) { 3.
4、 System.out.println(“I am an int.”); 4. } 5. void test(String s) { 6. System.out.println(“I am a string.”); 7. } 8. 9. public static void main(String args[]) {第15页共15页 10. Test t=new Test(); 11. char ch=“y”; 12. t.test(ch); 13. } 14. } Whichofthestatementsbelow
5、istrue?(Chooseone.)謀荞抟箧飆鐸怼类蒋薔。 A.Line5willnotcompile,becausevoidmethodscannotbeoverridden.厦礴恳蹒骈時盡继價骚。 B.Line12willnotcompile,becausethereisnoversionoftest()thatrakesacharargument.茕桢广鳓鯡选块网羈泪。 C.Thecodewillcompilebutwillthrowanexceptionatline12.鹅娅尽損鹌惨歷茏鴛賴。 D.Thecodewillc
6、ompileandproducethefollowingoutput:Iamanint.籟丛妈羥为贍偾蛏练淨。 E.Thecodewillcompileandproducethefollowingoutput:IamaString.預頌圣鉉儐歲龈讶骅籴。 解答:D 点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给voidtest(inti)方法.渗釤呛俨匀谔鱉调硯錦。 例题4: Whichofthefollowinglinesofcodewillcompilewithoute
7、rror?铙誅卧泻噦圣骋贶頂廡。 A.以下是引用片段: int i=0; if (i) { System.out.println(“Hi”); } B.以下是引用片段: boolean b=true; boolean b2=true; if(b==b2) { System.out.println(“So true”); } C.以下是引用片段: int i=1; int j=2; if(i==1
8、
9、 j==2) System.out.println(“OK”);第15页共15页 D.以下是引用片段: in
10、t i=1; int j=2; if (i==1 &
11、 j==2) System.out.println(“OK”); 解答:B,C 点评:选项A错,因为if语句后需要
此文档下载收益归作者所有