欢迎来到天天文库
浏览记录
ID:12617453
大小:30.50 KB
页数:8页
时间:2018-07-18
《scjp考试真题和解析scjp考试真题和解析.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、SCJP考试真题和解析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: How
2、canyouforcegarbagecollectionofanobject? A.Garbagecollectioncannotbeforced B.CallSystem.gc(). C.CallSystem.gc(),passinginareferencetotheobjecttobegarbagecollected. D.CallRuntime.gc(). E.Setallreferencestotheobjecttonewvalues(null,forexample). 解答:A 点评:在Java中垃圾收集是不能
3、被强迫立即执行的。调用System.gc()或Runtime.gc()静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。所以选项B、D不正确。选项C的错误在于,System.gc()方法是不接受参数的。选项E中的方法可以使对象在下次垃圾收集器运行时被收集。 例题3: Considerthefollowingclass: 1.classTest(inti){ 2.voidtest(inti){ 3.System.out.println(“Iamanint.”); 4.} 5.voidtest(Stri
4、ngs){ 6.System.out.println(“Iamastring.”); 7.} 8. 9.publicstaticvoidmain(Stringargs[]){ 10.Testt=newTest(); 11.charch=“y”; 12.t.test(ch); 13.} 14.} Whichofthestatementsbelowistrue?(Chooseone.) A.Line5willnotcompile,becausevoidmethodscannotbeoverridden. B
5、.Line12willnotcompile,becausethereisnoversionoftest()thatrakesacharargument. C.Thecodewillcompilebutwillthrowanexceptionatline12. D.Thecodewillcompileandproducethefollowingoutput:Iamanint. E.Thecodewillcompileandproducethefollowingoutput:IamaString. 解答:D 点评:在第12行,1
6、6位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给voidtest(inti)方法。1.Whichofthefollowingrangeofshortiscorrect? A.-27--27-1 B.0--216-1 C.?215--215-1 D.?231--231-1 翻译下面哪些是short型的取值范围。 答案 C 解析 短整型的数据类型的长度是16bits,有符号。另外需要说明的是java中所有的整(Integral)数(包括byte,short,int,long)全是有符号的。
7、 2.Whichdeclarationsofidentifiersarelegal? A.$persons B.TwoUsers C.*point D.thisE._endline 翻译下面哪些是合法的标识符。 答案 A,B,E 解析 Java的标识符可以以一个Unicode字符,下滑线(_),美元符($)开始,后续字符可以是前面的符号和数字,没有长度限制,大小写敏感,不能是保留字。 3.Whichstatementofassigningalongtypevariabletoahexadecimalvalueis
8、correct? A.longnumber=345L; B.longnumber=0345; C.longnumber=0345L; D.longnumber=0x345L 翻译哪些是将一个十六进制值赋值给一个
此文档下载收益归作者所有