日志 > 软件编程
![]()
SCJP考试题-2
![]() Exhibit: 1. public class X implements Runnable( 2. private int x; 3. private int y; 4. 5. public static void main(String[]args) 6. X that = new X(); 7. (new Thread(that)).start(); 8. (new Thread(that)).start(); 9. ) 10. 11. public void run() ( 12. for (;;) ( 13. x++; 14. y++; 15. System.out.printIn(“x=” + x + “, y = ” + y); 16. ) 17. ) 18. ) What is the result? A. Errors at lines 7 and 8 cause compilation to fail. B. The program prints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”). C. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”). D. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1” followed by “x=2, y=2”). Answer: D QUESTION NO: 107 Given: 1. public class SyncTest { 2. private int x; 3. private int y; 4. public synchronized void setX (int i) (x=1;) 5. public synchronized void setY (int i) (y=1;) 6. public synchronized void setXY(int 1)(set X(i); setY(i);) 7. public synchronized Boolean check() (return x !=y;) 8. ) Under which conditions will check () return true when called from a different class? A. Check() can never return true. B. Check() can return true when setXY is called by multiple threads. C. Check() can return true when multiple threads call setX and setY separately. D. Check() can only return true if SyncTest is changed to allow x and y to be set separately. Answer: A QUESTION NO: 108 Which is a method of the MouseMotionListener interface? A. Public void mouseDragged(MouseEvent) B. Public boolean mouseDragged(MouseEvent) C. Public void mouseDragged(MouseMotionEvent) D. Public boolean MouseDragged(MouseMotionEvent) E. Public boolean mouseDragged(MouseMotionEvent) Answer: A QUESTION NO: 109 Given: 1. String foo = “base”; 2. foo.substring(0,3); 3. foo.concat(“ket”); 4. foo += “ball”; 5. Type the value of foo at line 8. Answer: BASEBALL QUESTION NO 110 Given: 1. public class Test { 2. public static void leftshift(int i, int j) { 3. i<<=j; 4. } 5. public static void main(String args[]) { 6. int i = 4, j = 2; 7. leftshift(i, j); 8. System.out.printIn(i); 9. } 10. } What is the result? A. 2 B. 4 C. 8 D. 16 E. The code will not compile. Answer: B QUESTION NO 111 Given: 1. public class Foo { 2. private int val; 3. public foo(int v) (val = v;) } 4. public static void main (String [] args) { 5. Foo a = new Foo (10); 6. Foo b = new Foo (10); 7. Foo c = a; 8. int d = 10; 9. double e = 10.0; 10. } 11. } Which three logical expression evaluate to true? (Choose Three) A. (a ==c) B. (d ==e) C. (b ==d) D. (a ==b) E. (b ==c) F. (d ==10.0) Answer: A, B, F QUESTION NO 112 Exhibit: 1. public class X { 2. private static int a; 3. 5. public static void main (String[] args) { 6. modify (a); 7. } 8. 9. public static void modify (int a) { 10. a++; 11. } 12. } What is the result? A. The program runs and prints “0” B. The program runs and prints “1” C. The program runs but aborts with an exception. D. En error “possible undefined variable” at line 5 causes compilation to fail. F. En error “possible undefined variable” at line 10 causes compilation to fail. Answer: A QUESTION NO 113 Exhibit: 1. public class Test { 2. public static void replaceJ(string text) { 3. text.replace (‘j’, ‘l’); 4. } 5. 6. public static void main(String args[]) { 7. string text = new String (“java”) 8. replaceJ(text); 9. system.out.printIn(text); 10. } 11. } What is the result? A. The program prints “lava” B. The program prints “java” C. An error at line 7 causes compilation to fail. D. Compilation succeeds but the program throws an exception. Answer: B QUESTION NO 114 Which two are equivalent? (Choose Two) A. 3/2 B. 3<2 C. 3*4 D. 3<<2 E. 3*2^2 F. 3<<<2 Answer: C, D QUESTION NO 115 What is the numerical range of a char? A. 0 . . . 32767 B. 0 . . . 65535 C. ?C256 . . . 255 D. ?C32768 . . . 32767 E. Range is platform dependent. Answer: B QUESTION NO 116 Given: 1. public class Test { 2. public static void main (String []args) { 3. unsigned byte b = 0; 4. b--; 5. 6. } 7. } What is the value of b at line 5? A. -1 B. 255 C. 127 D. Compilation will fail. E. Compilation will succeed but the program will throw an exception at line 4. Answer: D QUESTION NO 117 Given: 1. public class Foo { 2. public void main (String [] args) { 3. system.out.printIn(“Hello World.”); 4. } 5. } What is the result? A. An exception is thrown. B. The code does no compile. C. “Hello World.” Is printed to the terminal. D. The program exits without printing anything. Answer: A QUESTION NO 118 Given: 1. //point X 2. public class foo ( 3. public static void main (String[]args) throws Exception { 4. java.io.printWriter out = new java.io.PrintWriter ( 5. new java.io.outputStreamWriter (System.out), true; 6. out.printIn(“Hello”); 7. } 8. } Which statement at PointX on line 1 allows this code to compile and run? A. Import java.io.*; B. Include java.io.*; C. Import java.io.PrintWriter; D. Include java.io.PrintWriter; E. No statement is needed. Answer: E ![]() |

了解各界捐助动态及捐赠渠道,请点击此处。
共0篇评论,第1页/共0页
批量删除 取消批量删除
共0篇评论,第1页/共0页