1Z0-851 | A Review Of Breathing 1Z0-851 dumps


Q151. Given:

22. StringBuilder sb1 = new StringBuilder("123");

23. String s1 = "123";

24. // insert code here

25. System.out.println(sb1 + " " + s1);

Which code fragment, inserted at line 24, outputs "123abc 123abc"?

A. sb1.append("abc"); s1.append("abc");

B. sb1.append("abc"); s1.concat("abc");

C. sb1.concat("abc"); s1.append("abc");

D. sb1.concat("abc"); s1.concat("abc");

E. sb1.append("abc"); s1 = s1.concat("abc");

F. sb1.concat("abc"); s1 = s1.concat("abc");

G. sb1.append("abc"); s1 = s1 + s1.concat("abc");

H. sb1.concat("abc"); s1 = s1 + s1.concat("abc");

Answer: E

Q152. Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)

A. When using versions of Java technology earlier than 5.0.

B. When sharing a StringBuffer among multiple threads.

C. When using the java.io class StringBufferInputStream.

D. When you plan to reuse the StringBuffer to build more than one string.

Answer: AB

Q153. Given:

5. class Atom {

6. Atom() { System.out.print("atom "); }

7. }

8. class Rock extends Atom {

9. Rock(String type) { System.out.print(type); }

10. }

11. public class Mountain extends Rock {

12. Mountain() {

13. super("granite ");

14. new Rock("granite ");

15. }

16. public static void main(String[] a) { new Mountain(); }

17. }

What is the result?

A. Compilation fails.

B. atom granite

C. granite granite

D. atom granite granite

E. An exception is thrown at runtime.

F. atom granite atom granite

Answer: F

Q154. Given:

12. public class Test {

13. public enum Dogs {collie, harrier};

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

15. Dogs myDog = Dogs.collie;

16. switch (myDog) {

17. case collie:

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

19. case harrier:

20. System.out.print("harrier ");

21. }

22. }

23. }

What is the result?

A. collie

B. harrier

C. Compilation fails.

D. collie harrier

E. An exception is thrown at runtime.

Answer: D

Q155. DRAG DROP

Click the Task button.

Answer:

Q156. Given:

1. public class Drink implements Comparable {

2. public String name;

3. public int compareTo(Object o) {

4. return 0;

5. }

6. }

and:

20. Drink one = new Drink();

21. Drink two = new Drink();

22. one.name= "Coffee";

23. two.name= "Tea";

24. TreeSet set = new TreeSet();

25. set.add(one);

26. set.add(two);

A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?

A. Tea

B. Coffee

C. Coffee Tea

D. Compilation fails.

E. The code runs with no output.

F. An exception is thrown at runtime.

Answer: B

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

Q158. Given:

1. public class Threads4 {

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

3. new Threads4().go();

4. }

5. public void go() {

6. Runnable r = new Runnable() {

7. public void run() {

8. System.out.print("foo");

9. }

10. };

11. Thread t = new Thread(r);

12. t.start();

13. t.start();

14. }

15. }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

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

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

Answer: B

Q159. 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: A

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