You will have instantaneous access to our Oracle 1Z0-851 exam goods after confirming the payment at Pass4sure. The particular Oracle 1Z0-851 practice questions with verified answers tend to be compiled and also revised by our subject matter specialists. Our own experts have make excellent contributions to our Oracle Oracle exam products. Weve got many consumers who have obtained the Oracle 1Z0-851 certification. We tend to be proud of the substantial passing ratio since many of us start.

2021 Sep oracle ocp 1z0-851:

Q171. Given a pre-generics implementation of a method:

11. public static int sum(List list) {

12. int sum = 0;

13. for ( Iterator iter = list.iterator(); iter.hasNext(); ) {

14. int i = ((Integer)iter.next()).intValue();

15. sum += i;

16. }

17. return sum;

18. }

What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose

three.)

A. Remove line 14.

B. Replace line 14 with "int i = iter.next();".

C. Replace line 13 with "for (int i : intList) {".

D. Replace line 13 with "for (Iterator iter : intList) {".

E. Replace the method declaration with "sum(List<int> intList)".

F. Replace the method declaration with "sum(List<Integer> intList)".

Answer: ACF


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


Q173. Given:

10. abstract public class Employee {

11. protected abstract double getSalesAmount();

12. public double getCommision() {

13. return getSalesAmount() * 0.15;

14. }

15. }

16. class Sales extends Employee {

17. // insert method here

18. }

Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.)

A. double getSalesAmount() { return 1230.45; }

B. public double getSalesAmount() { return 1230.45; }

C. private double getSalesAmount() { return 1230.45; }

D. protected double getSalesAmount() { return 1230.45; }

Answer: BD


Q174. Given:

11. class Snoochy {

12. Boochy booch;

13. public Snoochy() { booch = new Boochy(this); }

14. }

15.

16. class Boochy {

17. Snoochy snooch;

18. public Boochy(Snoochy s) { snooch = s; }

19. } And the statements:

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

22. Snoochy snoog = new Snoochy();

23. snoog = null;

24. // more code here

25. }

Which statement is true about the objects referenced by snoog, snooch, and booch immediately after line 23 executes?

A. None of these objects are eligible for garbage collection.

B. Only the object referenced by booch is eligible for garbage collection.

C. Only the object referenced by snoog is eligible for garbage collection.

D. Only the object referenced by snooch is eligible for garbage collection.

E. The objects referenced by snooch and booch are eligible for garbage collection.

Answer: E


Q175. Which statement is true?

A. A class's finalize() method CANNOT be invoked explicitly.

B. super.finalize() is called implicitly by any overriding finalize() method.

C. The finalize() method for a given object is called no more than once by the garbage collector.

D. The order in which finalize() is called on two objects is based on the order in which the two objects

became finalizable.

Answer: C


1Z0-851  practice exam

Rebirth oracle as 1z0-851:

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


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


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


Q179. Click the Exhibit button. Which statement is true about the classes and interfaces in the exhibit?


A. Compilation will succeed for all classes and interfaces.

B. Compilation of class C will fail because of an error in line 2.

C. Compilation of class C will fail because of an error in line 6.

D. Compilation of class AImpl will fail because of an error in line 2.

Answer: C


Q180. Given:

1. d is a valid, non-null Date object

2. df is a valid, non-null DateFormat object set to the current locale What outputs the current locale's

country name and the appropriate version of d's date?

A. Locale loc = Locale.getLocale();

System.out.println(loc.getDisplayCountry()

+ " " + df.format(d));

B. Locale loc = Locale.getDefault();

System.out.println(loc.getDisplayCountry()

+ " " + df.format(d));

C. Locale loc = Locale.getLocale();

System.out.println(loc.getDisplayCountry()

+ " " + df.setDateFormat(d));

D. Locale loc = Locale.getDefault();

System.out.println(loc.getDisplayCountry()

+ " " + df.setDateFormat(d));

Answer: B