
Oracle Java Standard Edition 6 Programmer Certified Professional - 1Z0-851 Exam Questions
QUESTION NO: 1
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"?
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"?
Correct Answer: D
QUESTION NO: 2
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?
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?
Correct Answer: B
QUESTION NO: 3
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?
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?
Correct Answer: B
QUESTION NO: 4
Click the Exhibit button.
Given:
31.public void method() {
32.A a = new A();
33.a.method1();
34.}
Which statement is true if a TestException is thrown on line 3 of class B?

Click the Exhibit button.
Given:
31.public void method() {
32.A a = new A();
33.a.method1();
34.}
Which statement is true if a TestException is thrown on line 3 of class B?

Correct Answer: D
QUESTION NO: 5
Click the Exhibit button. What is the output if the main() method is run?

Click the Exhibit button. What is the output if the main() method is run?

Correct Answer: A
QUESTION NO: 6
Given a correctly compiled class whose source code is:
1.package com.sun.sjcp;
2.public class Commander {
3.public static void main(String[] args) {
4.// more code here
5.}
6.}
Assume that the class file is located in /foo/com/sun/sjcp/, the current directory is /foo/, and that the classpath contains "." (current directory). Which command line correctly runs Commander?
Given a correctly compiled class whose source code is:
1.package com.sun.sjcp;
2.public class Commander {
3.public static void main(String[] args) {
4.// more code here
5.}
6.}
Assume that the class file is located in /foo/com/sun/sjcp/, the current directory is /foo/, and that the classpath contains "." (current directory). Which command line correctly runs Commander?
Correct Answer: D
QUESTION NO: 7
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?
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?
Correct Answer: B
QUESTION NO: 8
Given:
5.class Payload {
6.private int weight;
7.public Payload (int w) { weight = w; }
8.public void setWeight(int w) { weight = w; }
9.public String toString() { return Integer.toString(weight); }
10.}
11.public class TestPayload {
12.static void changePayload(Payload p) { /* insert code */ }
13.public static void main(String[] args) {
14.Payload p = new Payload(200);
15.p.setWeight(1024);
16.changePayload(p);
17.System.out.println("p is " + p);
18.} }
Which code fragment, inserted at the end of line 12, produces the output p is 420?
Given:
5.class Payload {
6.private int weight;
7.public Payload (int w) { weight = w; }
8.public void setWeight(int w) { weight = w; }
9.public String toString() { return Integer.toString(weight); }
10.}
11.public class TestPayload {
12.static void changePayload(Payload p) { /* insert code */ }
13.public static void main(String[] args) {
14.Payload p = new Payload(200);
15.p.setWeight(1024);
16.changePayload(p);
17.System.out.println("p is " + p);
18.} }
Which code fragment, inserted at the end of line 12, produces the output p is 420?
Correct Answer: A
QUESTION NO: 9
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?
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?
Correct Answer: B
QUESTION NO: 10
Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)
Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)
Correct Answer: B,D
QUESTION NO: 11
Given:
1.public class Mule {
2.public static void main(String[] args) {
3.boolean assert = true;
4.if(assert) {
5.System.out.println("assert is true");
6.}
7.}
8.}
Which command-line invocations will compile?
Given:
1.public class Mule {
2.public static void main(String[] args) {
3.boolean assert = true;
4.if(assert) {
5.System.out.println("assert is true");
6.}
7.}
8.}
Which command-line invocations will compile?
Correct Answer: A
QUESTION NO: 12
Given:
10.class One {
11.void foo() { }
12.}
13.class Two extends One {
14.//insert method here
15.}
Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)
Given:
10.class One {
11.void foo() { }
12.}
13.class Two extends One {
14.//insert method here
15.}
Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)
Correct Answer: C,D,E
QUESTION NO: 13
Click the Exhibit button. What is the output if the main() method is run?

Click the Exhibit button. What is the output if the main() method is run?

Correct Answer: A
QUESTION NO: 14
Given:
11.public class Person {
12.private name;
13.public Person(String name) {
14.this.name = name;
15.}
16.public int hashCode() {
17.return 420;
18.}
19.}
Which statement is true?
Given:
11.public class Person {
12.private name;
13.public Person(String name) {
14.this.name = name;
15.}
16.public int hashCode() {
17.return 420;
18.}
19.}
Which statement is true?
Correct Answer: A




