1Z0-851 | 9 Tips For Leading 1Z0-851 dumps


Q161. Given:

3. import java.util.*;

4. public class Hancock {

5. // insert code here

6. list.add("foo");

7. }

8. }

Which two code fragments, inserted independently at line 5, will compile without warnings? (Choose two.)

A. public void addStrings(List list) {

B. public void addStrings(List<String> list) {

C. public void addStrings(List<? super String> list) {

D. public void addStrings(List<? extends String> list) {

Answer: BC

Q162. Given:

11. public void go(int x) {

12. assert (x > 0);

13. switch(x) {

14. case 2: ;

15. default: assert false;

16. }

17. }

18. private void go2(int x) { assert (x < 0); }

Which statement is true?

A. All of the assert statements are used appropriately.

B. Only the assert statement on line 12 is used appropriately.

C. Only the assert statement on line 15 is used appropriately.

D. Only the assert statement on line 18 is used appropriately.

E. Only the assert statements on lines 12 and 15 are used appropriately.

F. Only the assert statements on lines 12 and 18 are used appropriately.

G. Only the assert statements on lines 15 and 18 are used appropriately.

Answer: G

Q163. Given:

11. class Alpha {

12. public void foo() { System.out.print("Afoo "); }

13. }

14. public class Beta extends Alpha {

15. public void foo() { System.out.print("Bfoo "); }

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

17. Alpha a = new Beta();

18. Beta b = (Beta)a;

19. a.foo();

20. b.foo();

21. }

22. }

What is the result?

A. Afoo Afoo

B. Afoo Bfoo

C. Bfoo Afoo

D. Bfoo Bfoo

E. Compilation fails.

F. An exception is thrown at runtime.

Answer: D

Q164. Given two files, GrizzlyBear.java and Salmon.java:

1. package animals.mammals;

2.

3. public class GrizzlyBear extends Bear {

4. void hunt() {

5. Salmon s = findSalmon();

6. s.consume();

7. }

8. }

1. package animals.fish;

2.

3. public class Salmon extends Fish {

4. public void consume() { /* do stuff */ }

5. }

If both classes are in the correct directories for their packages, and the Mammal class correctly defines the

findSalmon() method, which change allows this code to compile?

A. add import animals.mammals.*; at line 2 in Salmon.java

B. add import animals.fish.*; at line 2 in GrizzlyBear.java

C. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.java

D. add import animals.mammals.GrizzlyBear.*; at line 2 in Salmon.java

Answer: B

Q165. Given:

1. interface A { public void aMethod(); }

2. interface B { public void bMethod(); }

3. interface C extends A,B { public void cMethod(); }

4. class D implements B {

5. public void bMethod(){}

6. }

7. class E extends D implements C {

8. public void aMethod(){}

9. public void bMethod(){}

10. public void cMethod(){}

11. }

What is the result?

A. Compilation fails because of an error in line 3.

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

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

D. If you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.

E. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5.

F. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

Answer: F

Q166. Given:

1. public class TestOne {

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

3. Thread.sleep(3000);

4. System.out.println("sleep");

5. }

6. }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

C. The code executes normally and prints "sleep".

D. The code executes normally, but nothing is printed.

Answer: C

Q167. Given that the current directory is empty, and that the user has read and write privileges to the current

directory, and the following:

1. import java.io.*;

2. public class Maker {

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

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

5. File f = new File(dir, "f");

6. }

7. }

Which statement is true?

A. Compilation fails.

B. Nothing is added to the file system.

C. Only a new file is created on the file system.

D. Only a new directory is created on the file system.

E. Both a new file and a new directory are created on the file system.

Answer: B

Q168. DRAG DROP

Click the Task button.

Answer:

Q169. DRAG DROP

Click the Task button.

Answer: