1Z0-851 | What 100% Correct 1Z0-851 exam dumps Is?


Q71. 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: DF

Q72. Given:

11. class ClassA {}

12. class ClassB extends ClassA {}

13. class ClassC extends ClassA {}

and:

21. ClassA p0 = new ClassA();

22. ClassB p1 = new ClassB();

23. ClassC p2 = new ClassC();

24. ClassA p3 = new ClassB();

25. ClassA p4 = new ClassC();

Which three are valid? (Choose three.)

A. p0 = p1;

B. p1 = p2;

C. p2 = p4;

D. p2 = (ClassC)p1;

E. p1 = (ClassB)p3;

F. p2 = (ClassC)p4;

Answer: AEF

Q73. Which 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 int[2]; a[0]=100; a[1]=200; }

C. static final int[] a = new int[2]{ 100,200 };

D. static final int[] a;

static void init() { a = new int[3]; a[0]=100; a[1]=200; }

Answer: AB

Q74. Given:

3. import java.util.*;

4. public class Mapit {

5. public static void main(String[] args) {

6. Set<Integer> set = new HashSet<Integer>();

7. Integer i1 = 45;

8. Integer i2 = 46;

9. set.add(i1);

10. set.add(i1);

11. set.add(i2); System.out.print(set.size() + " ");

12. set.remove(i1); System.out.print(set.size() + " ");

13. i2 = 47;

14. set.remove(i2); System.out.print(set.size() + " ");

15. }

16. }

What is the result?

A. 2 1 0

B. 2 1 1

C. 3 2 1

D. 3 2 2

E. Compilation fails.

F. An exception is thrown at runtime.

Answer: B

Q75. Given that the current directory is empty, and that the user has read and write permissions, and the following:

11. import java.io.*;

12. public class DOS {

13. public static void main(String[] args) {

14. File dir = new File("dir");

15. dir.mkdir();

16. File f1 = new File(dir, "f1.txt");

17. try {

18. f1.createNewFile();

19. } catch (IOException e) { ; }

20. File newDir = new File("newDir");

21. dir.renameTo(newDir);

22. }

23. }

Which statement is true?

A. Compilation fails.

B. The file system has a new empty directory named dir.

C. The file system has a new empty directory named newDir.

D. The file system has a directory named dir, containing a file f1.txt.

E. The file system has a directory named newDir, containing a file f1.txt.

Answer: E

Q76. Click the Exhibit button. Given: ClassA a = new ClassA(); a.methodA(); What is the result?

A. Compilation fails.

B. ClassC is displayed.

C. The code runs with no output.

D. An exception is thrown at runtime.

Answer: D

Q77. Given:

1. public class BuildStuff {

2. public static void main(String[] args) {

3. Boolean test = new Boolean(true);

4. Integer x = 343;

5. Integer y = new BuildStuff().go(test, x);

6. System.out.println(y);

7. }

8. int go(Boolean b, int i) {

9. if(b) return (i/7);

10. return (i/49);

11. }

12. }

What is the result?

A. 7

B. 49

C. 343

D. Compilation fails.

E. An exception is thrown at runtime.

Answer: B

Q78. Given:

11. interface DeclareStuff {

12. public static final int EASY = 3;

13. void doStuff(int t); }

14. public class TestDeclare implements DeclareStuff {

15. public static void main(String [] args) {

16. int x = 5;

17. new TestDeclare().doStuff(++x);

18. }

19. void doStuff(int s) {

20. s += EASY + ++s;

21. System.out.println("s " + s);

22. }

23. }

What is the result?

A. s 14

B. s 16

C. s 10

D. Compilation fails.

E. An exception is thrown at runtime.

Answer: D

Q79. Given:

11. static void test() throws Error {

12. if (true) throw new AssertionError();

13. System.out.print("test ");

14. }

15. public static void main(String[] args) {

16. try { test(); }

17. catch (Exception ex) { System.out.print("exception "); }

18. System.out.print("end ");

19. }

What is the result?

A. end

B. Compilation fails.

C. exception end

D. exception test end

E. A Throwable is thrown by main.

F. An Exception is thrown by main.

Answer: E

Q80. Given:

1. class Pizza {

2. java.util.ArrayList toppings;

3. public final void addTopping(String topping) {

4. toppings.add(topping);

5. }

6. }

7. public class PepperoniPizza extends Pizza {

8. public void addTopping(String topping) {

9. System.out.println("Cannot add Toppings");

10. }

11. public static void main(String[] args) {

12. Pizza pizza = new PepperoniPizza();

13. pizza.addTopping("Mushrooms");

14. }

15. }

What is the result?

A. Compilation fails.

B. Cannot add Toppings

C. The code runs with no output.

D. A NullPointerException is thrown in Line 4.

Answer: A