1Z0-851 | how many questions of 1Z0-851 dumps?


Q131. Given:

1. class Alligator {

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

3. int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

4. int [][]y = x;

5. System.out.println(y[2][1]);

6. }

7. }

What is the result?

A. 2

B. 3

C. 4

D. 6

E. 7

F. Compilation fails.

Answer: E

Q132. Given:

23. Object [] myObjects = {

24. new Integer(12),

25. new String("foo"),

26. new Integer(5),

27. new Boolean(true)

28. };

29. Arrays.sort(myObjects);

30. for(int i=0; i<myObjects.length; i++) {

31. System.out.print(myObjects[i].toString());

32. System.out.print(" ");

33. }

What is the result?

A. Compilation fails due to an error in line 23.

B. Compilation fails due to an error in line 29.

C. A ClassCastException occurs in line 29.

D. A ClassCastException occurs in line 31.

E. The value of all four objects prints in natural order.

Answer: C

Q133. DRAG DROP

Click the Task button.

Answer:

Q134. A team of programmers is involved in reviewing a proposed design for a new utility class. After some discussion, they realize that the current design allows other classes to access methods in the utility class that should be accessible only to methods within the utility class itself. What design issue has the team discovered?

A. Tight coupling

B. Low cohesion

C. High cohesion

D. Loose coupling

E. Weak encapsulation

F. Strong encapsulation

Answer: E

Q135. Click the Exhibit button. What is the result?

A. Value is: 8

B. Compilation fails.

C. Value is: 12

D. Value is: -12

E. The code runs with no output.

F. An exception is thrown at runtime.

Answer: A

Q136. Click the Exhibit button. Given:

25. try {

26. A a = new A();

27. a.method1();

28. } catch (Exception e) {

29. System.out.print("an error occurred");

30. }

Which two statements are true if a NullPointerException is thrown on line 3 of class C? (Choose two.)

A. The application will crash.

B. The code on line 29 will be executed.

C. The code on line 5 of class A will execute.

D. The code on line 5 of class B will execute.

E. The exception will be propagated back to line 27.

Answer: BE

Q137. Given:

1. public class Threads3 implements Runnable {

2. public void run() {

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

4. }

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

6. Thread t = new Thread(new Threads3());

7. t.run();

8. t.run();

9. t.start();

10. }

11. }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

C. The code executes and prints "running".

D. The code executes and prints "runningrunning".

E. The code executes and prints "runningrunningrunning".

Answer: E

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

Q139. Given that: Gadget has-a Sprocket and Gadget has-a Spring and Gadget is-a Widget and Widget has-a

Sprocket Which two code fragments represent these relationships? (Choose two.)

A. class Widget { Sprocket s; }

class Gadget extends Widget { Spring s; }

B. class Widget { }

class Gadget extends Widget { Spring s1; Sprocket s2; }

C. class Widget { Sprocket s1; Spring s2; }

class Gadget extends Widget { }

D. class Gadget { Spring s; }

class Widget extends Gadget{ Sprocket s; }

E. class Gadget { }

class Widget extends Gadget{ Sprocket s1; Spring s2; }

F. class Gadget { Spring s1; Sprocket s2; }

class Widget extends Gadget{ }

Answer: AC

Q140. Given:

1. public class Donkey {

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

3. boolean assertsOn = false;

4. assert (assertsOn) : assertsOn = true;

5. if(assertsOn) {

6. System.out.println("assert is on");

7. }

8. }

9. }

If class Donkey is invoked twice, the first time without assertions enabled, and the second time with assertions enabled, what are the results?

A. no output

B. no output

assert is on

C. assert is on

D. no output

An AssertionError is thrown.

E. assert is on

An AssertionError is thrown.

Answer: D