《2022年SCJP题库》由会员分享,可在线阅读,更多相关《2022年SCJP题库(31页珍藏版)》请在金锄头文库上搜索。
1、yModule 1-JAVA 基本一、选择题:Question 1Given:35. String #name = Jane Doe;36. int $age=24;37. Double _height = 123.5;38. double temp = 37.5;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标记符以 字母,下划线
2、,或者$开始Question 2Given:11. public class Test 12. public static void main(String args) 13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if(x=4) & !b2)18. System.out.print(l );19. System.out.print(2 );20. if (b2 = true) & b1)21. System.out.print(3);22. 23. What is the result?A. 2B. 3C. 1
3、 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional is thrown at runtime.Answer: D 注意20行,=为赋值,不要被骗Question 3Given:42. public class ClassA 43. public int getValue() 44. int value=0;45. boolean setting = true;46. String title=Hello;47. if (value | (setting & title = Hello) return 1; 48. if (value =
4、 1 & title.equals(Hello) return 2; 49. 50. And:70. ClassA a = new ClassA();71. a.getValue();What is the result?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47行value为int类型不是booleanQuestion 4Given:11. public void testIfA() 12. if(tes
5、tIfB(True) 13. System.out.println(True);14. else 15. System.out.println(Not true);16. 17. 18. public Boolean testIfB(String str) 19. return Boolean.valueOf(str);20. What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because o
6、f an error at line 12.E. Compilation fails because of an error at line 19.Answer: A 19行,如果str为true则返回ture,否则返回falseQuestion 5Given:11. public static void main(String args) 12. Integer i = new Integer(1) + new Integer(2);13. switch(i) 14. case 3: System.out.println(three); break;15. default: System.o
7、ut.println(other); break;16. 17. What is the result?A. threeB. otherC. An exception is thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15.Answer: A 就是两个Integer类型相加Question 6Give
8、n:11. public static void main(String args) 12. String str = null;13. if (str = null) 14. System.out.println(null);15. else (str.length() = 0) 16. System.out.println(zero);17. else 18. System.out.println(some);19. 20. What is the result?A. nullB. zeroC. someD. Compilation fails.E. An exception is thr
9、own at runtime.Answer: D 这题真恶心 15行少个ifQuestion 7Given:10.int x=0;11.int y=10;12. do l3. y-;14. +x;15. while (x 5);16. System.out.print(x + , + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: B (91,82,73,64,55)没啥争议Question 8Given:25.int x=12;26. while (x 10,因此直接跳出循环,输出x=12Question 9Given:35. in
10、t x= 10;36. do 37. x-;38. while(x 10);How many times will line 37 be executed?A. ten timesB. zero timesC. one to me timesD. more than ten timesAnswer: D 死循环Question 10Given:11. public static void main(String args) 12. for (int i=0;i6) break;14. 15. System.out.println(i);16. What is the result?A. 6B.
11、 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime.Answer: E 15行i超过了作用域Question 11Given:55. int x= 1, 2,3,4, 5;56. int y =x;57. System.out.println(y2);Which is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in
12、line 55.D. Compilation will fail because of an error in line 56.Answer: B 没争议,考察数组下标是从0开始Question 12Which two code fragments(片段) correctly(对旳) create and initialize a static array of int elements? (Choose two.)A. static final int a = 100,200 ;B. static final int a;static a=new int2; a0=100; a1=200;
13、C. static final int a = new int2 100,200 ;D. static final int a;static void init() a = new int3; a0=100; a1=200; Answer: AB c不能指定长度,d不能在init措施中赋值,要么在static代码块中Question 13Given:11. public static void main(String args) 12. Object obj = new int 1,2,3 ;13. int someArray = (int)obj;14. for (int i: someAr
14、ray) System.out.print(i + )15. What is the result?A. 1 2 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach循环遍历数组Question 14Given:11. String elements = for, te