1Z0-851 | Actual Java 1Z0-851 exam dumps


Q101. Given:

11. String test = "Test A. Test B. Test C.";

12. // insert code here

13. String[] result = test.split(regex);

Which regular expression, inserted at line 12, correctly splits test into "Test A", "Test B", and "Test C"?

A. String regex = "";

B. String regex = " ";

C. String regex = ".*";

D. String regex = "\s";

E. String regex = "\.\s*";

F. String regex = "\w[ .] +";

Answer: E

Q102. DRAG DROP

Answer:

Q103. Given:

3. class Employee {

4. String name; double baseSalary;

5. Employee(String name, double baseSalary) {

6. this.name = name;

7. this.baseSalary = baseSalary;

8. }

9. }

10. public class SalesPerson extends Employee {

11. double commission;

12. public SalesPerson(String name, double baseSalary, double commission) {

13. // insert code here

14. }

15. }

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

A. super(name, baseSalary);

B. this.commission = commission;

C. super();

this.commission = commission;

D. this.commission = commission;

super();

E. super(name, baseSalary);

this.commission = commission;

F. this.commission = commission;

super(name, baseSalary);

G. super(name, baseSalary, commission);

Answer: AE

Q104. DRAG DROP

Click the Task button.

Answer:

Q105. Given:

10. public class Foo {

11. static int[] a;

12. static { a[0]=2; }

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

14. }

Which exception or error will be thrown when a programmer attempts to run this code?

A. java.lang.StackOverflowError

B. java.lang.IllegalStateException

C. java.lang.ExceptionInInitializerError

D. java.lang.ArrayIndexOutOfBoundsException

Answer: C

Q106. Given:

11. public static Collection get() {

12. Collection sorted = new LinkedList();

13. sorted.add("B"); sorted.add("C"); sorted.add("A");

14. return sorted;

15. }

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

17. for (Object obj: get()) {

18. System.out.print(obj + ", ");

19. }

20. }

What is the result?

A. A, B, C,

B. B, C, A,

C. Compilation fails.

D. The code runs with no output.

E. An exception is thrown at runtime.

Answer: B

Q107. Given:

21. class Money {

22. private String country = "Canada";

23. public String getC() { return country; }

24. }

25. class Yen extends Money {

26. public String getC() { return super.country; }

27. }

28. public class Euro extends Money {

29. public String getC(int x) { return super.getC(); }

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

31. System.out.print(new Yen().getC() + " " + new Euro().getC());

32. }

33. }

What is the result?

A. Canada

B. null Canada

C. Canada null

D. Canada Canada

E. Compilation fails due to an error on line 26.

F. Compilation fails due to an error on line 29.

Answer: E

Q108. Given:

3. public class Breaker {

4. static String o = "";

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

6. z:

7. o = o + 2;

8. for(int x = 3; x < 8; x++) {

9. if(x==4) break;

10. if(x==6) break z;

11. o = o + x;

12. }

13. System.out.println(o);

14. }

15. }

What is the result?

A. 23

B. 234

C. 235

D. 2345

E. 2357

F. 23457

G. Compilation fails.

Answer: G

Q109. Click the Exhibit button.

Given:

25. A a = new A();

26. System.out.println(a.doit(4, 5));

What is the result?

A. Line 26 prints "a" to System.out.

B. Line 26 prints "b" to System.out.

C. An exception is thrown at line 26 at runtime.

D. Compilation of class A will fail due to an error in line 6.

Answer: A

Q110. Given:

11. public class Rainbow {

12. public enum MyColor {

13. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);

14. private final int rgb;

15. MyColor(int rgb) { this.rgb = rgb; }

16. public int getRGB() { return rgb; }

17. };

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

19. // insert code here

20. }

21. }

Which code fragment, inserted at line 19, allows the Rainbow class to compile?

A. MyColor skyColor = BLUE;

B. MyColor treeColor = MyColor.GREEN;

C. if(RED.getRGB() < BLUE.getRGB()) { }

D. Compilation fails due to other error(s) in the code.

E. MyColor purple = new MyColor(0xff00ff);

F. MyColor purple = MyColor.BLUE + MyColor.RED;

Answer: B