1Z0-851 | 10 Tips For Update 1Z0-851 pdf


Q91. 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

Q92. Given:

11. public interface A { public void m1(); }

12.

13. class B implements A { }

14. class C implements A { public void m1() { } }

15. class D implements A { public void m1(int x) { } }

16. abstract class E implements A { }

17. abstract class F implements A { public void m1() { } }

18. abstract class G implements A { public void m1(int x) { } }

What is the result?

A. Compilation succeeds.

B. Exactly one class does NOT compile.

C. Exactly two classes do NOT compile.

D. Exactly four classes do NOT compile.

E. Exactly three classes do NOT compile.

Answer: C

Q93. Given a pre-generics implementation of a method:

11. public static int sum(List list) {

12. int sum = 0;

13. for ( Iterator iter = list.iterator(); iter.hasNext(); ) {

14. int i = ((Integer)iter.next()).intValue();

15. sum += i;

16. }

17. return sum;

18. }

What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose

three.)

A. Remove line 14.

B. Replace line 14 with "int i = iter.next();".

C. Replace line 13 with "for (int i : intList) {".

D. Replace line 13 with "for (Iterator iter : intList) {".

E. Replace the method declaration with "sum(List<int> intList)".

F. Replace the method declaration with "sum(List<Integer> intList)".

Answer: ACF

Q94. Given:

1. public class Threads5 {

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

3. new Thread(new Runnable() {

4. public void run() {

5. System.out.print("bar");

6. }}).start();

7. }

8. }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

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

D. The code executes normally, but nothing prints.

Answer: C

Q95. A programmer must create a generic class MinMax and the type parameter of MinMax must implement

Comparable. Which implementation of MinMax will compile?

A. class MinMax<E extends Comparable<E>> {

E min = null;

E max = null;

public MinMax() {}

public void put(E value) { /* store min or max */ }

B. class MinMax<E implements Comparable<E>> {

E min = null;

E max = null;

public MinMax() {}

public void put(E value) { /* store min or max */ }

C. class MinMax<E extends Comparable<E>> {

<E> E min = null;

<E> E max = null;

public MinMax() {}

public <E> void put(E value) { /* store min or max */ }

D. class MinMax<E implements Comparable<E>> {

<E> E min = null;

<E> E max = null;

public MinMax() {}

public <E> void put(E value) { /* store min or max */ }

Answer: A

Q96. Given:

34. HashMap props = new HashMap();

35. props.put("key45", "some value");

36. props.put("key12", "some other value");

37. props.put("key39", "yet another value");

38. Set s = props.keySet();

39. // insert code here What, inserted at line 39, will sort the keys in the props HashMap?

A. Arrays.sort(s);

B. s = new TreeSet(s);

C. Collections.sort(s);

D. s = new SortedSet(s);

Answer: B

Q97. Given:

11. public class Test {

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

13. int x = 5;

14. boolean b1 = true;

15. boolean b2 = false;

16.

17. if ((x == 4) && !b2 )

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

19. System.out.print("2 ");

20. if ((b2 = true) && b1 )

21. System.out.print("3 ");

22. }

23. }

What is the result?

A. 2

B. 3

C. 1 2

D. 2 3

E. 1 2 3

F. Compilation fails.

G. An exception is thrown at runtime.

Answer: D

Q98. Given:

11. class Snoochy {

12. Boochy booch;

13. public Snoochy() { booch = new Boochy(this); }

14. }

15.

16. class Boochy {

17. Snoochy snooch;

18. public Boochy(Snoochy s) { snooch = s; }

19. } And the statements:

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

22. Snoochy snoog = new Snoochy();

23. snoog = null;

24. // more code here

25. }

Which statement is true about the objects referenced by snoog, snooch, and booch immediately after line 23 executes?

A. None of these objects are eligible for garbage collection.

B. Only the object referenced by booch is eligible for garbage collection.

C. Only the object referenced by snoog is eligible for garbage collection.

D. Only the object referenced by snooch is eligible for garbage collection.

E. The objects referenced by snooch and booch are eligible for garbage collection.

Answer: E

Q99. Given:

11. public interface A { public void m1(); }

12.

13. class B implements A { }

14. class C implements A { public void m1() { } }

15. class D implements A { public void m1(int x) { } }

16. abstract class E implements A { }

17. abstract class F implements A { public void m1() { } }

18. abstract class G implements A { public void m1(int x) { } }

What is the result?

A. Compilation succeeds.

B. Exactly one class does NOT compile.

C. Exactly two classes do NOT compile.

D. Exactly four classes do NOT compile.

E. Exactly three classes do NOT compile.

Answer: C

Q100. Given

11. public interface Status {

12. /* insert code here */ int MY_VALUE = 10;

13. } Which three are valid on line

12?

(Choose three.)

A. final

B. static

C. native

D. public

E. private

F. abstract

G. protected

Answer: ABD