1Z0-851 | A Review Of Simulation 1Z0-851 pdf


Q141. Given:

11. public enum Title {

12. MR("Mr."), MRS("Mrs."), MS("Ms.");

13. private final String title;

14. private Title(String t) { title = t; }

15. public String format(String last, String first) {

16. return title + " " + first + " " + last;

17. }

18. }

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

20. System.out.println(Title.MR.format("Doe", "John"));

21. }

What is the result?

A. Mr. John Doe

B. An exception is thrown at runtime.

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

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

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

Answer: A

Q142. Given:

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

12. try {

13. args = null;

14. args[0] = "test";

15. System.out.println(args[0]);

16. } catch (Exception ex) {

17. System.out.println("Exception");

18. } catch (NullPointerException npe) {

19. System.out.println("NullPointerException");

20. }

21. }

What is the result?

A. test

B. Exception

C. Compilation fails.

D. NullPointerException

Answer: C

Q143. Given:

1. public class Target {

2. private int i = 0;

3. public int addOne(){

4. return ++i;

5. }

6. } And:

1. public class Client {

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

3. System.out.println(new Target().addOne());

4. }

5. }

Which change can you make to Target without affecting Client?

A. Line 4 of class Target can be changed to return i++;

B. Line 2 of class Target can be changed to private int i = 1;

C. Line 3 of class Target can be changed to private int addOne(){

D. Line 2 of class Target can be changed to private Integer i = 0;

Answer: D

Q144. Given:

11. public class ItemTest {

12. private final int id;

13. public ItemTest(int id) { this.id = id; }

14. public void updateId(int newId) { id = newId; }

15.

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

17. ItemTest fa = new ItemTest(42);

18. fa.updateId(69);

19. System.out.println(fa.id);

20. }

21. }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

C. The attribute id in the ItemTest object remains unchanged.

D. The attribute id in the ItemTest object is modified to the new value.

E. A new ItemTest object is created with the preferred value in the id attribute.

Answer: A

Q145. Given classes defined in two different files:

1. package util;

2. public class BitUtils {

3. private static void process(byte[] b) {}

4. }

1. package app;

2. public class SomeApp {

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

4. byte[] bytes = new byte[256];

5. // insert code here

6. }

7. }

What is required at line 5 in class SomeApp to use the process method of BitUtils?

A. process(bytes);

B. BitUtils.process(bytes);

C. app.BitUtils.process(bytes);

D. util.BitUtils.process(bytes);

E. import util.BitUtils.*; process(bytes);

F. SomeApp cannot use the process method in BitUtils.

Answer: F

Q146. Given:

11. String test = "a1b2c3";

12. String[] tokens = test.split("\d");

13. for(String s: tokens) System.out.print(s + " ");

What is the result?

A. a b c

B. 1 2 3

C. a1b2c3

D. a1 b2 c3

E. Compilation fails.

F. The code runs with no output.

G. An exception is thrown at runtime.

Answer: A

Q147. Given:

11. String test = "a1b2c3";

12. String[] tokens = test.split("\d");

13. for(String s: tokens) System.out.print(s + " ");

What is the result?

A. a b c

B. 1 2 3

C. a1b2c3

D. a1 b2 c3

E. Compilation fails.

F. The code runs with no output.

G. An exception is thrown at runtime.

Answer: A

Q148. Given:

3. public class Batman {

4. int squares = 81;

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

6. new Batman().go();

7. }

8. void go() {

9. incr(++squares);

10. System.out.println(squares);

11. }

12. void incr(int squares) { squares += 10; }

13. }

What is the result?

A. 81

B. 82

C. 91

D. 92

E. Compilation fails.

F. An exception is thrown at runtime.

Answer: B

Q149. Given a class Repetition:

1. package utils;

2.

3. public class Repetition {

4. public static String twice(String s) { return s + s; }

5. } and given another class Demo:

1. // insert code here

2.

3. public class Demo {

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

5. System.out.println(twice("pizza"));

6. }

7. }

Which code should be inserted at line 1 of Demo.java to compile and run Demo to print "pizzapizza"?

A. import utils.*;

B. static import utils.*;

C. import utils.Repetition.*;

D. static import utils.Repetition.*;

E. import utils.Repetition.twice();

F. import static utils.Repetition.twice;

G. static import utils.Repetition.twice;

Answer: F

Q150. Given:

12. Date date = new Date();

13. df.setLocale(Locale.ITALY);

14. String s = df.format(date);

The variable df is an object of type DateFormat that has been initialized in line 11. What is the result if this

code is run on December 14, 2000?

A. The value of s is 14-dic-2000.

B. The value of s is Dec 14, 2000.

C. An exception is thrown at runtime.

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

Answer: D