Oracle 1Z0-851 Actual Free Exam Questions & Community Discussion

  • Exam Code/Number: 1Z0-851
  • Exam Name/Title: Java Standard Edition 6 Programmer Certified Professional Exam
  • Certification Provider: Oracle
  • Corresponding Certification: OCJP
  • Exam Questions: 290
  • Updated On: May 26, 2026
Given that the current directory is empty, and that the user has read and write privileges to the current directory, and the following:
1.import java.io.*;
2.public class Maker {
3.public static void main(String[] args) {
4.File dir = new File("dir");
5.File f = new File(dir, "f");
6.}
7.}
Which statement is true?
Correct Answer: E Vote an answer
Given:
22.public void go() {
23.String o = "";
24.z:
25.for(int x = 0; x < 3; x++) {
26.for(int y = 0; y < 2; y++) {
27.if(x==1) break;
28.if(x==2 && y==1) break z;
29.o = o + x + y;
30.}
31.}
32.System.out.println(o);
33.}
What is the result when the go() method is invoked?
Correct Answer: B Vote an answer
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?
Correct Answer: E Vote an answer
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?
Correct Answer: D Vote an answer
Which statement is true?
Correct Answer: D Vote an answer
Given:
10.interface Foo {}
11.class Alpha implements Foo {}
12.class Beta extends Alpha {}
13.class Delta extends Beta {
14.public static void main( String[] args ) {
15.Beta x = new Beta();
16.// insert code here
17.}
18.}
Which code, inserted at line 16, will cause a java.lang.ClassCastException?
Correct Answer: B Vote an answer
Given: public class NamedCounter {
private final String name;
private int count;
public NamedCounter(String name) { this.name = name; }
public String getName() { return name; }
public void increment() { count++; }
public int getCount() { return count; }
public void reset() { count = 0; }
} Which three changes should be made to adapt this class to be used safely by multiple threads? (Choose three.)
Correct Answer: A,C,E Vote an answer
DRAG DROP
Click the Task button.
Correct Answer:
Given:
11.public void genNumbers() {
12.ArrayList numbers = new ArrayList();
13.for (int i=0; i<10; i++) {
14.int value = i * ((int) Math.random());
15.Integer intObj = new Integer(value);
16.numbers.add(intObj);
17.}
18.System.out.println(numbers);
19.}
Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection?
Correct Answer: C Vote an answer
Given:
11.public interface A { public void m1(); }
12.13.
class B implements A { }
14.class C implements A { public void m1() { } }
15.class D implements A { public void m1(int x) { } }
16.abstract class E implements A { }
17.abstract class F implements A { public void m1() { } }
18.abstract class G implements A { public void m1(int x) { } } What is the result?
Correct Answer: C Vote an answer
Which Man class properly represents the relationship "Man has a best friend who is a Dog"?
Correct Answer: D Vote an answer
Given:
11.static void test() throws Error {
12.if (true) throw new AssertionError();
13.System.out.print("test ");
14.}
15.public static void main(String[] args) {
16.try { test(); }
17.catch (Exception ex) { System.out.print("exception "); }
18.System.out.print("end ");
19.}
What is the result?
Correct Answer: D Vote an answer
Given:
11.public class Commander {
12.public static void main(String[] args) {
13.String myProp = /* insert code here */
14.System.out.println(myProp);
15.}
16.}
and the command line: java -Dprop.custom=gobstopper Commander Which two, placed on line 13, will produce the output gobstopper? (Choose two.)
Correct Answer: A,B Vote an answer
0
0
0
10