JAVA认证历年真题:SCJP考试真题和解析.pdf
《JAVA认证历年真题:SCJP考试真题和解析.pdf》由会员分享,可在线阅读,更多相关《JAVA认证历年真题:SCJP考试真题和解析.pdf(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、JAVA认证历年真题:SCJP考试真题和解析(1)JAVA认证历年真题:SCJP考试真题和解析例题1:Choose the three valid identifiers from those listed below.A.IDoLikeTheLongNameCiassB.$byteC.constD._okE.3_case解答:A,B,D点评:Jav a中的标示符必须是字母、美元符($)或下划线(_)开头。关键字与保留字不能作为标示符。选项C 中的const是 Java的保留字,所以不能作标示符。选项E 中的3_case以数字开头,违反了 Java的规则。例题2:How can you for
2、ce garbage collection of an object?A.Garbage collection cannot be forcedB.Call System.gc().C.Call System.gc(),passing in a reference to the object to be garbage collected.D.Call Runtime.gc().E.Set all references to the object to new values(null,for example).解答:A点评:在 Java中垃圾收集是不能被强迫立即执行的。调用System.gc(
3、)或 Runtime.gc。静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。所以选项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(4tI am an int.);4.)5.void test(String s)6.System.out.printlnCI am a string.);7.8.9.pu
4、blic static void main(String args)10.Test t=new Test();l l.c h a rc h ;12.t.test(ch);13.14.Which of the statements below is true?(Choose one.)A.Line 5 will not compile,because void methods cannot be overridden.B.Line 12 will not compile,because there is no version of test()that rakes a char argument
5、.C.The code will compile but will throw an exception at line 12.D.The code will compile and produce the following output:I am an int.E.The code will compile and produce the following output:I am a String.解答:D点评:在 第 12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。Question No:1Given:
6、1.public class test(2.public static void main(String args)3.inti=OxFFFFFFFl;4.int j=i;5.6.7.)What is the decimal value of j at line 5?A.OB.1C.14D.-15E.An error at line 3 causes compilation to fail.F.An error at line 4 causes compilation to fail.Answer:DQuestion No:2Given:Integer i=new Integer(42);Lo
7、ng 1 =new Long(42);Double d=new Double(42.0);Which two expressions evaluate to True?(Choose Two)A.(i=1)B.(i=d)C.(d=1)D.(i.equals(d)E.(d.equals(i)F.(i.equals(42)Answer:D,EQuestion No:3Exhibit:1.public class test(2.private static int j=0;3.4.private static boolean methodB(int k)(5.j+=k;6.return true;6
8、.)7.8.public static void methodA(int i)9.boolean b:10.b=i<lOlmethodB(4);l l.b=i<1011 methodB(8);12.)13.14.public static void main(String args(15.methodA(0);16.system.out.println(j);17.)18.)What is the result?A.The program prints A”B.The program prihat is the output?Answer:5Question No:5Given:1
9、.public class Foo 2.public static void main(String args)3.StringBuffer a=new StringBuffer();4.StringBuffer b=new StringBuffer(B”);5.operate(a,b);6.system.out.printlna+b);7.)8.static void operate(StringBuffer x,StringBuffer y)9.x.append y;10.y=x;11.)12.)What is the result?A.The code compiles and prin
10、tsB.The code compiles and prints A,A”.C.The code compiles and printsD.The code compiles and printsE.The code compiles and prints AB,AB”.F.The code does not compile because cannot be overloaded for StringBuffer.Answer:D IIIQuestion No:6Exhibit:1.Public class test(2.Public static void stringReplace(St
11、ring text)(3.Text=text.replace(j,i);4.)5.6.public static void bufferReplace(StringBuffer text)(7.text=text.append(“C”)8.)9.10.public static void main(String args)(11.String textString=new String(java);12.StringBuffer text BufferString=new StringBuffer(“java”);13.14.stringReplace(textString);15.Buffe
12、rReplace(textBuffer);16.17.System.out.printin(textString+textBuffer);18.19.)What is the output?Answer:javajavaCQuestion No:7Exhibit:1.public class test 2.public static void add3(Integer i)3.int val=i.intValue();4.val+=3;5.i=new Integer(val);6.)7.8.public static void main(String args )9.Integer i=new
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVA 认证 历年 SCJP 考试 解析
限制150内