1Z0-851 | Far out 1Z0-851 Exam Study Guides With New Update Exam Questions


Q61. DRAG DROP

Click the Task button.

Answer:

Q62. Click the Exhibit button. Which three code fragments, added individually at line 29, produce the output 100? (Choose three.)

A. n = 100;

B. i.setX( 100 );

C. o.getY().setX( 100 );

D. i = new Inner(); i.setX( 100 );

E. o.setY( i ); i = new Inner(); i.setX( 100 );

F. i = new Inner(); i.setX( 100 ); o.setY( i );

Answer: BCF

Q63. Given:

11. public class Person {

12. private name;

13. public Person(String name) {

14. this.name = name;

15. }

16. public int hashCode() {

17. return 420;

18. }

19. }

Which statement is true?

A. The time to find the value from HashMap with a Person key depends on the size of the map.

B. Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.

C. Inserting a second Person object into a HashSet will cause the first Person object to be removed as a

duplicate.

D. The time to determine whether a Person object is contained in a HashSet is constant and does NOT

depend on the size of the map.

Answer: A

Q64. Given:

10. interface A { void x(); }

11. class B implements A { public void x() {} public void y() {} }

12. class C extends B { public void x() {} } And:

20. java.util.List<A> list = new java.util.ArrayList<A>();

21. list.add(new B());

22. list.add(new C());

23. for (A a : list) {

24. a.x();

25. a.y();

26. }

What is the result?

A. The code runs with no output.

B. An exception is thrown at runtime.

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

D. Compilation fails because of an error in line 21.

E. Compilation fails because of an error in line 23.

F. Compilation fails because of an error in line 25.

Answer: F

Q65. Given:

1. public class TestString3 {

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

3. // insert code here

5. System.out.println(s);

6. }

7. }

Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.)

A. String s = "123456789";

s = (s-"123").replace(1,3,"24") - "89";

B. StringBuffer s = new StringBuffer("123456789");

C. delete(0,3).replace(1,3,"24").delete(4,6);

D. StringBuffer s = new StringBuffer("123456789");

E. substring(3,6).delete(1,3).insert(1, "24");

F. StringBuilder s = new StringBuilder("123456789");

G. substring(3,6).delete(1,2).insert(1, "24");

H. StringBuilder s = new StringBuilder("123456789");

I. delete(0,3).delete(1,3).delete(2,5).insert(1, "24");

Answer: BE

Q66. Which Man class properly represents the relationship "Man has a best friend who is a Dog"?

A. class Man extends Dog { }

B. class Man implements Dog { }

C. class Man { private BestFriend dog; }

D. class Man { private Dog bestFriend; }

E. class Man { private Dog<bestFriend>; }

F. class Man { private BestFriend<dog>; }

Answer: D

Q67. 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: E

Q68. Given:

11. Float pi = new Float(3.14f);

12. if (pi > 3) {

13. System.out.print("pi is bigger than 3. ");

14. }

15. else {

16. System.out.print("pi is not bigger than 3. ");

17. }

18. finally {

19. System.out.println("Have a nice day.");

20. }

What is the result?

A. Compilation fails.

B. pi is bigger than 3.

C. An exception occurs at runtime.

D. pi is bigger than 3. Have a nice day.

E. pi is not bigger than 3. Have a nice day.

Answer: A

Q69. Given:

10. class One {

11. void foo() { }

12. }

13. class Two extends One {

14. //insert method here

15. }

Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)

A. int foo() { /* more code here */ }

B. void foo() { /* more code here */ }

C. public void foo() { /* more code here */ }

D. private void foo() { /* more code here */ }

E. protected void foo() { /* more code here */ }

Answer: BCE

Q70. Given:

1. public class GC {

2. private Object o;

3. private void doSomethingElse(Object obj) { o = obj; }

4. public void doSomething() {

5. Object o = new Object();

6. doSomethingElse(o);

7. o = new Object();

8. doSomethingElse(null);

9. o = null;

10. }

11. }

When the doSomething method is called, after which line does the Object created in line 5 become available for garbage collection?

A. Line 5

B. Line 6

C. Line 7

D. Line 8

E. Line 9

F. Line 10

Answer: D