8 public static void modify String s 9 s What is the result 310 035

8 public static void modify string s 9 s what is the

This preview shows page 119 - 124 out of 143 pages.

8. public static void modify (String s) { 9. s += “world!”; 10. } 11. } What is the result?
Image of page 119
310 - 035 Leading the way in IT testing and certification tools, -119 - A. The program runs and prints “Hello” B. An error causes compilation to fail. C. The program runs and prints “Hello world!” D. The program runs but aborts with an exception. Answer: A QUESTION NO: 96 Which two are equivalent? (Choose Two) A. 16>4 B. 16/2 C. 16*4 D. 16>>2 E. 16/2^2 F. 16>>>2 Answer: D, E QUESTION NO: 97 Exhibit: 1. public class X { 2. public static void main (String[]args) { 3. int [] a = new int [1] 4. modify(a); 5. System.out.printIn(a[0]); 6. } 7. 8. public static void modify (int[] a) { 9. a[0] ++; 10. } 11. } 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. An error “possible undefined variable” at line 4 causes compilation to fail. E. An error “possible undefined variable” at line 9 causes compilation to fail.
Image of page 120
310 - 035 Leading the way in IT testing and certification tools, -120 - Answer: B QUESTION NO: 98 Given: 25. public class Foo { 26. public static void main (String [] args) { 27. StringBuffer a = new StringBuffer (“A”); 28. StringBuffer b = new StringBuffer (“B”); 29. operate (a,b); 30. system.out.printIn{a + “,” +b}; 31. ) 32. static void operate (StringBuffer x, StringBuffer y) { 33. y.append {x}; 34. y = x; 35. ) 36. } What is the result? A. The code compiles and prints “A,B”. B. The code compiles and prints “A, BA”. C. The code compiles and prints “AB, B”. D. The code compiles and prints “AB, AB”. E. The code compiles and prints “BA, BA”. F. The code does not compile because “+” cannot be overloaded for stringBuffer. Answer: B QUESTION NO: 99 Given: 8. public class X { 9. public static void main (String[] args) { 10. byte b = 127; 11. byte c = 126; 12. byte d = b + c; 13. } 14. } Which statement is true? A. Compilation succeeds and d takes the value 253. B. Line 5 contains an error that prevents compilation.
Image of page 121
310 - 035 Leading the way in IT testing and certification tools, -121 - C. Line 5 throws an exception indicating “Out of range” D. Line 3 and 4 contain error that prevent compilation. E. The compilation succeeds and d takes the value of 1. Answer: B QUESTION NO: 100 Given: 1. public class WhileFoo { 2. public static void main (String []args) { 3. int x= 1, y = 6; 4. while (y--) {x--;} 5. system.out.printIn(“x=” + x “y =” + y); 6. } 7. } What is the result? A. The output is x = 6 y = 0 B. The output is x = 7 y = 0 C. The output is x = 6 y = -1 D. The output is x = 7 y = -1 E. Compilation will fail. Answer: E QUESTION NO: 101 Which statement is true? A. The Error class is a untimeException. B. No exceptions are subclasses of Error. C. Any statement that may throw an Error must be enclosed in a try block. D. Any statement that may throw an Exception must be enclosed in a try block. E. Any statement that may thro a runtimeException must be enclosed in a try block. Answer: D QUESTION NO: 102 Exhibit:
Image of page 122
310 - 035 Leading the way in IT testing and certification tools, -122 - 1. int I=1, j=0 2.
Image of page 123
Image of page 124

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture