Exam Code: 1Z0-851 (Practice Exam Latest Test Questions VCE PDF)
Exam Name: Java Standard Edition 6 Programmer Certified Professional Exam
Certification Provider: Oracle
Free Today! Guaranteed Training- Pass 1Z0-851 Exam.

2021 Sep oracle as 1z0-851:

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


Q102. DRAG DROP


Answer:


Q103. Given:

1. public class TestSeven extends Thread {

2. private static int x;

3. public synchronized void doThings() {

4. int current = x;

5. current++;

6. x = current;

7. }

8. public void run() {

9. doThings();

10. }

11.}

Which statement is true?

A. Compilation fails.

B. An exception is thrown at runtime.

C. Synchronizing the run() method would make the class thread-safe.

D. The data in variable "x" are protected from concurrent access problems.

E. Declaring the doThings() method as static would make the class thread-safe.

F. Wrapping the statements within doThings() in a synchronized(new Object()) { } block would make the

class thread-safe.

Answer: E


Q104. Given:

1. class Super {

2. private int a;

3. protected Super(int a) { this.a = a; }

4. } ...

11. class Sub extends Super {

12. public Sub(int a) { super(a); }

13. public Sub() { this.a = 5; }

14. }

Which two, independently, will allow Sub to compile? (Choose two.)

A. Change line 2 to:

public int a;

B. Change line 2 to:

protected int a;

C. Change line 13 to:

public Sub() { this(5); }

D. Change line 13 to:

public Sub() { super(5); }

E. Change line 13 to:

public Sub() { super(a); }

Answer: CD


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


1Z0-851  exam answers

Improve 1z0-851 vs 310-065:

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


Q107. Given:

11. Float pi = new Float(3.14f);

12. if (pi > 3) {

13. System.out.print("pi is bigger than 3. ");

14. }

15. else {

16. System.out.print("pi is not bigger than 3. ");

17. }

18. finally {

19. System.out.println("Have a nice day.");

20. }

What is the result?

A. Compilation fails.

B. pi is bigger than 3.

C. An exception occurs at runtime.

D. pi is bigger than 3. Have a nice day.

E. pi is not bigger than 3. Have a nice day.

Answer: A


Q108. Given:

1. public class LineUp {

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

3. double d = 12.345;

4. // insert code here

5. }

6. }

Which code fragment, inserted at line 4, produces the output | 12.345|?

A. System.out.printf("|%7d| n", d);

B. System.out.printf("|%7f| n", d);

C. System.out.printf("|%3.7d| n", d);

D. System.out.printf("|%3.7f| n", d);

E. System.out.printf("|%7.3d| n", d);

F. System.out.printf("|%7.3f| n", d);

Answer: F


Q109. Given:

3. interface Animal { void makeNoise(); }

4. class Horse implements Animal {

5. Long weight = 1200L;

6. public void makeNoise() { System.out.println("whinny"); }

7. }

8. public class Icelandic extends Horse {

9. public void makeNoise() { System.out.println("vinny"); }

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

11. Icelandic i1 = new Icelandic();

12. Icelandic i2 = new Icelandic();

13. Icelandic i3 = new Icelandic();

14. i3 = i1; i1 = i2; i2 = null; i3 = i1;

15. }

16. }

When line 15 is reached, how many objects are eligible for the garbage collector?

A. 0

B. 1

C. 2

D. 3

E. 4

F. 6

Answer: E


Q110. Given:

1. class ClassA {

2. public int numberOfInstances;

3. protected ClassA(int numberOfInstances) {

4. this.numberOfInstances = numberOfInstances;

5. }

6. }

7. public class ExtendedA extends ClassA {

8. private ExtendedA(int numberOfInstances) {

9. super(numberOfInstances);

10. }

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

12. ExtendedA ext = new ExtendedA(420);

13. System.out.print(ext.numberOfInstances);

14. }

15. }

Which statement is true?

A. 420 is the output.

B. An exception is thrown at runtime.

C. All constructors must be declared public.

D. Constructors CANNOT use the private modifier.

E. Constructors CANNOT use the protected modifier.

Answer: A