Skip to main content

1Z0-852 Real Exam Questions

Java Standard Edition 6 Programmer Certified Professional Upgrade

96 questions available · Page 1 of 10

Updated Exam DumpsVerified AnswersPass Guarantee

Get Complete Exam Dumps
Question 1 Single choice

Given:

21. abstract class C1 {
22. public C1() { System.out.print(1); }
23. }
24. class C2 extends C1 {
25. public C2() { System.out.print(2); }
26. }
27. class C3 extends C2 {
28. public C3() { System.out.println(3); }
29. }
30. public class Ctest {
31. public static void main(String[] a) { new C3(); }
32. }

What is the result?

  1. A

    3

  2. B

    23

  3. C

    32

  4. D

    123

  5. E

    321

  6. F

    Compilation fails.

  7. G

    An exception is thrown at runtime.

Show answer and explanation

Correct answer: D

Question 2 Multiple choice

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

  1. A

    declare reset() using the synchronized keyword

  2. B

    declare getName() using the synchronized keyword

  3. C

    declare getCount() using the synchronized keyword

  4. D

    declare the constructor using the synchronized keyword

  5. E

    declare increment() using the synchronized keyword

Show answer and explanation

Correct answers: A, C, E

Question 3 Single choice

Which can appropriately be thrown by a programmer using Java SE technology to create a desktop application?

  1. A

    ClassCastException

  2. B

    NullPointerException

  3. C

    NoClassDefFoundError

  4. D

    NumberFormatException

  5. E

    ArrayIndexOutOfBoundsException

Show answer and explanation

Correct answer: D

Question 4 Single choice

Given:

1. public class Breaker2 {
2. static String o = "";
3. public static void main(String[] args) {
4. z:
5. for(int x = 2; x < 7; x++) {
6. if(x==3) continue;
7. if(x==5) break z;
8. o = o + x;
9. }
10. System.out.println(o);
11. }
12. }

What is the result?

  1. A

    2

  2. B

    24

  3. C

    234

  4. D

    246

  5. E

    2346

  6. F

    Compilation fails.

Show answer and explanation

Correct answer: B

Question 5 Multiple choice

Given that c is a reference to a valid java.io.Console object, which two code fragments read a line of text from the console? (Choose two.)

  1. A

    String s = c.readLine();

  2. B

    char[] c = c.readLine();

  3. C

    String s = c.readConsole();

  4. D

    char[] c = c.readConsole();

  5. E

    String s = c.readLine("%s", "name ");

  6. F

    char[] c = c.readLine("%s", "name ");

Show answer and explanation

Correct answers: A, E

Question 6 Single choice

Given:

1. package test;
2.

3. class Target {
4. public String name = "hello";
5. }

What can directly access and change the value of the variable name?

  1. A

    any class

  2. B

    only the Target class

  3. C

    any class in the test package

  4. D

    any class that extends Target

Show answer and explanation

Correct answer: C

Question 7 Single choice

Given:

11. public void testIfA() {
12. if (testIfB("True")) {
13. System.out.println("True");
14. } else {
15. System.out.println("Not true");
16. }
17. }
18. public Boolean testIfB(String str) {
19. return Boolean.valueOf(str);
20. }

What is the result when method testIfA is invoked?

  1. A

    True

  2. B

    Not true

  3. C

    An exception is thrown at runtime.

  4. D

    Compilation fails because of an error at line 12.

  5. E

    Compilation fails because of an error at line 19.

Show answer and explanation

Correct answer: A

Question 8 Single choice

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|?

  1. A

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

  2. B

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

  3. C

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

  4. D

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

  5. E

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

  6. F

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

Show answer and explanation

Correct answer: F

Question 9 Single choice

Given:

11. class X { public void foo() { System.out.print("X "); } } 12.
13. public class SubB extends X {
14. public void foo() throws RuntimeException {
15. super.foo();
16. if (true) throw new RuntimeException();
17. System.out.print("B ");

18. }
19. public static void main(String[] args) {
20. new SubB().foo();
21. }
22. }

What is the result?

  1. A

    X, followed by an Exception.

  2. B

    No output, and an Exception is thrown.

  3. C

    Compilation fails due to an error on line 14.

  4. D

    Compilation fails due to an error on line 16.

  5. E

    Compilation fails due to an error on line 17.

  6. F

    X, followed by an Exception, followed by B.

Show answer and explanation

Correct answer: A

Question 10 Single choice

Given:

1. public class TestOne implements Runnable {
2. public static void main (String[] args) throws Exception {
3. Thread t = new Thread(new TestOne());
4. t.start();
5. System.out.print("Started");
6. t.join();
7. System.out.print("Complete");
8. }
9. public void run() {
10. for (int i = 0; i < 4; i++) {
11. System.out.print(i);
12. }
13. }
14. }

What can be a result?

  1. A

    Compilation fails.

  2. B

    An exception is thrown at runtime.

  3. C

    The code executes and prints "StartedComplete".

  4. D

    The code executes and prints "StartedComplete0123".

  5. E

    The code executes and prints "Started0123Complete".

Show answer and explanation

Correct answer: E