35道scjp考试真题精解

35道scjp考试真题精解

ID:18149853

大小:91.00 KB

页数:15页

时间:2018-09-14

35道scjp考试真题精解_第1页
35道scjp考试真题精解_第2页
35道scjp考试真题精解_第3页
35道scjp考试真题精解_第4页
35道scjp考试真题精解_第5页
资源描述:

《35道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:  Howcanyouforcegarbagecollect

2、ionofanobject?  A.Garbagecollectioncannotbeforced  B.CallSystem.gc().  C.CallSystem.gc(),passinginareferencetotheobjecttobegarbagecollected.  D.CallRuntime.gc().  E.Setallreferencestotheobjecttonewvalues(null,forexample).  解答:A  点评:在Java中垃圾收集是不能被强迫立即执行的。调用System.gc()或Runtime.gc()静态方法不能

3、保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。所以选项B、D不正确。选项C的错误在于,System.gc()方法是不接受参数的。选项E中的方法可以使对象在下次垃圾收集器运行时被收集。  例题3:以下是引用片段:  Consider the following class:  1. class Test(int i) {  2. void test(int i) {  3. System.out.println(“I am an int.”);  4. }  5. void test(String s) {  6. System.out.println(

4、“I am a string.”);  7. }  8.  9. public static void main(String args[]) {  10. Test t=new Test();第15页共15页  11. char ch=“y”;  12. t.test(ch);  13. }  14. }  Whichofthestatementsbelowistrue?(Chooseone.)  A.Line5willnotcompile,becausevoidmethodscannotbeoverridden.  B.Line12willnotcompile,

5、becausethereisnoversionoftest()thatrakesacharargument.  C.Thecodewillcompilebutwillthrowanexceptionatline12.  D.Thecodewillcompileandproducethefollowingoutput:Iamanint.  E.Thecodewillcompileandproducethefollowingoutput:IamaString.  解答:D  点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运

6、行时传给voidtest(inti)方法。  例题4:  Whichofthefollowinglinesofcodewillcompilewithouterror?  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

7、

8、 j=

9、=2)  System.out.println(“OK”);  D.第15页共15页以下是引用片段:  int i=1;  int j=2;  if (i==1 &

10、 j==2)  System.out.println(“OK”);  解答:B,C  点评:选项A错,因为if语句后需要一个boolean类型的表达式。逻辑操作有^、&、

11、和&&、

12、

13、,但是“&

14、”是非法的,所以选项D不正确。  例题5:以下是引用片段:  Which two demonstrate a "has a" relationship? (Choose two)  A. public in

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。