1Z0-852 | Leading Oracle 1Z0-852 examcollection


Q11. Given: 

11.

 public static void main(String[] args) { 

12.

 Object obj = new int[] { 1, 2, 3 }; 

13.

 int[] someArray = (int[])obj; 

14.

 for (int i : someArray) System.out.print(i + " "); 

15.

 } 

What is the result? 

A. 1 2 3 

B. 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:

Explanation: 

Q12. Given that c is a reference to a valid java.io.Console object, which two code fragments read a line of text from the console? (Choose two.) 

A. String s = c.readLine(); 

B. char[] c = c.readLine(); 

C. String s = c.readConsole(); 

D. char[] c = c.readConsole(); 

E. String s = c.readLine("%s", "name "); 

F. char[] c = c.readLine("%s", "name "); 

Answer: A,E 

Explanation: 

Q13. Given: 

15.

 public class Pass2 { 

16.

 public void main(String [] args) { 

17.

 int x = 6; 

18.

 Pass2 p = new Pass2(); 

19.

 p.doStuff(x); 

20.

 System.out.print(" main x = " + x); 

21.

 } 

22. 

23.

 void doStuff(int x) { 

24.

 System.out.print(" doStuff x = " + x++); 

25.

 } 

26.

 } 

And the command-line invocations: 

javac Pass2.java java Pass2 5 

What is the result? 

A. Compilation fails. 

B. An exception is thrown at runtime. 

C. doStuff x = 6 main x = 6 

D. doStuff x = 6 main x = 7 

E. doStuff x = 7 main x = 6 

F. doStuff x = 7 main x = 7 

Answer:

Explanation: 

Q14. Given: 

11.

 public interface A111 { 

12.

 String s = "yo"; 

13.

 public void method1(); 

14.

 } 

17. interface B { } 

20.

 interface C extends A111, B { 

21.

 public void method1(); 

22.

 public void method1(int x); 

23.

 } 

What is the result? 

A. Compilation succeeds. 

B. Compilation fails due to multiple errors. 

C. Compilation fails due to an error only on line 20. 

D. Compilation fails due to an error only on line 21. 

E. Compilation fails due to an error only on line 22. 

F. Compilation fails due to an error only on line 12. 

Answer:

Explanation: 

Q15. Given: 

11.

 public class PingPong implements Runnable { 

12.

 synchronized void hit(long n) { 

13.

 for(int i = 1; i < 3; i++) 

14.

 System.out.print(n + "-" + i + " "); 

15.

 } 

16.

 public static void main(String[] args) { 

17.

 new Thread(new PingPong()).start(); 

18.

 new Thread(new PingPong()).start(); 

19.

 } 

20.

 public void run() { 

21.

 hit(Thread.currentThread().getId()); 

22.

 } 

23.

 } 

Which two statements are true? (Choose two.) 

A. The output could be 8-1 7-2 8-2 7-1 

B. The output could be 7-1 7-2 8-1 6-1 

C. The output could be 8-1 7-1 7-2 8-2 

D. The output could be 8-1 8-2 7-1 7-2 

Answer: C,D 

Explanation: 

Q16. Which two code fragments are most likely to cause a StackOverflowError? (Choose two.) 

A. int []x = {1,2,3,4,5}; 

for(int y = 0; y < 6; y++) 

System.out.println(x[y]); 

B. static int[] x = {7,6,5,4}; 

static { x[1] = 8; 

x[4] = 3; } 

C. for(int y = 10; y < 10; y++) 

doStuff(y); 

D. void doOne(int x) { doTwo(x); } 

void doTwo(int y) { doThree(y); } 

void doThree(int z) { doTwo(z); } 

E. for(int x = 0; x < 1000000000; x++) 

doStuff(x); 

F. void counter(int i) { counter(++i); } 

Answer: D,F 

Explanation: 

Q17. Given: 

21.

 abstract class C1 { 

22.

 public C1() { System.out.print(1); } 

23.

 } 

24.

 class C2 extends C1 { 

25.

 public C2() { System.out.print(2); } 

26.

 } 

27.

 class C3 extends C2 { 

28.

 public C3() { System.out.println(3); } 

29.

 } 

30.

 public class Ctest { 

31.

 public static void main(String[] a) { new C3(); } 

32.

 } 

What is the result? 

A. 3 

B. 23 

C. 32 

D. 123 

E. 321 

F. Compilation fails. 

G. An exception is thrown at runtime. 

Answer:

Explanation: 

15. Given: 

1.

 public class A { 

2.

 public void doit() { 

3.

 } 

4.

 public String doit() { 

5.

 return "a"; 

6.

 } 

7.

 public double doit(int x) { 

8.

 return 1.0; 

9.

 } 

10.

 } 

What is the result? 

A. An exception is thrown at runtime. 

B. Compilation fails because of an error in line 7. 

C. Compilation fails because of an error in line 4. 

D. Compilation succeeds and no runtime errors with class A occur. 

Answer:

Explanation: 

Q18. Given: 

5.

 import java.util.Date; 

6.

 import java.text.DateFormat; 

21.

 DateFormat df 

22.

 Date date = new Date(); 

23.

 // insert code here 

24.

 String s = df.format(date); 

Which code fragment, inserted at line 23, allows the code to compile? 

A. df = new DateFormat(); 

B. df = Date.getFormat(); 

C. df = date.getFormat(); 

D. df = DateFormat.getFormat(); 

E. df = DateFormat.getInstance(); 

Answer:

Explanation: 

Q19. RAG DROP 

Click the Task button. 

Answer: 

Q20. Given that Triangle implements Runnable, and: 

31.

 void go() throws Exception { 

32.

 Thread t = new Thread(new Triangle()); 

33.

 t.start(); 

34.

 for(int x = 1; x < 100000; x++) { 

35.

 //insert code here 

36.

 if(x%100 == 0) System.out.print("g"); 

37.

 } } 

38.

 public void run() { 

39.

 try { 

40.

 for(int x = 1; x < 100000; x++) { 

41.

 // insert the same code here 

42.

 if(x%100 == 0) System.out.print("t"); 

43.

 } 

44.

 } catch (Exception e) { } 

45.

 } 

Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute? (Choose two.) 

A. Thread.wait(); 

B. Thread.join(); 

C. Thread.yield(); 

D. Thread.sleep(1); 

E. Thread.notify(); 

Answer: C,D 

Explanation: