별의 공부 블로그 🧑🏻‍💻
728x90
728x170

QUESTION 1

Given:

 

public class Threads2 implements Runnable {

public void run() { System.out.println("run.");

throw new RuntimeException("Problem");

}

 

public static void main(String[] args) { Thread t = new Thread(new Threads2()); t.start();

System.out.println("End of method.");

}

}

 

Which two can be results? (Choose two.)

 

A.    java.lang.RuntimeException: Problem

B.    run.

java.lang.RuntimeException: Problem

C.    End of method. java.lang.RuntimeException: Problem

D.    End of method. run.

java.lang.RuntimeException: Problem

E.    run.

java.lang.RuntimeException: Problem End of method.

 

Correct Answer: DE Section: All Explanation

 

Explanation/Reference: End  of  method. run.

Exception in thread "Thread-0" java.lang.RuntimeException: Problem at Threads2.run(Threads2.java:5)

at java.lang.Thread.run(Unknown Source)

 

QUESTION 2

Which two statements are true? (Choose two.)

 

A.    It is possible for more than two threads to deadlock at once.

B.    The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state.

C.    Deadlocked threads release once their sleep() method's sleep duration has expired.

D.    Deadlocking can occur only when the wait(), notify(),  and notifyAll() methods are used incorrectly.

E.    It is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly.

F.    If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield().

 

Correct Answer: AF Section: All Explanation

 

Explanation/Reference:


 

QUESTION 3

Given:

 

void waitForSignal() {

Object obj = new Object();

synchronized (Thread.currentThread()) { obj.wait();

obj.notify();

}

}

 

Which statement is true?

 

A.    This code can throw an InterruptedException.

B.    This code can throw an IllegalMonitorStateException.

C.    This code can throw a TimeoutException after ten minutes.

D.    Reversing the order of obj.wait() and obj.notify() might cause this method to complete  normally.

E.    A call to notify() or notifyAll() from another thread might cause this method to complete normally.

F.    This code does NOT compile unless "obj.wait()" is replaced with "((Thread) obj).wait()".

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

Not quite sure about the answer, because first of all this code will not compile:

 

Threads2.java:15: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown

obj.wait();

^

1 error

 

QUESTION 4

Given:

 

class PingPong2 {

synchronized void hit(long n) {

for(int i = 1; i < 3; i++) System.out.print(n + "-" + i + " ");

}

}

 

public class Tester implements Runnable {

static PingPong2 pp2 = new PingPong2();

 

public static void main(String[] args) { new Thread(new Tester()).start(); new Thread(new Tester()).start();

}

 

public void run() { pp2.hit(Thread.currentThread().getId()); }

}

 

Which statement is true?

 

A.    The output could be 5-1 6-1 6-2 5-2

B.    The output could be 6-1 6-2 5-1 5-2

C.    The output could be 6-1 5-2 6-2 5-1

D.    The output could be 6-1 6-2 5-1 7-1


 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 5

Given:

 

public class Threads4 {

public static void main (String[] args) {

new Threads4().go();

}

 

public void go() {

Runnable r = new Runnable() {

public void run() { System.out.print("foo");

}

};

Thread t = new Thread(r); t.start();

t.start();

}

}

 

What is the result?

 

A.    Compilation fails.

B.    An exception is thrown at runtime.

C.    The code executes normally and prints "foo".

D.    The code executes normally, but nothing is printed.

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

Exception in thread "main" java.lang.IllegalThreadStateException at java.lang.Thread.start(Unknown Source)

at Threads4.go(Threads4.java:14) at Threads4.main(Threads4.java:3)

foo

 

QUESTION 6

Given:

 

public abstract class Shape {

private int x;

private int y;

 

public abstract void draw();

 

public void setAnchor(int x, int y) {

this.x = x;

this.y = y;

}

}

 

Which two classes use the Shape class correctly? (Choose two.)


 

A.    public class Circle implements Shape {

private int radius;

}

B.    public abstract class Circle extends Shape {

private int radius;

}

C.    public class Circle extends Shape {

private int radius;

public void draw();

}

D.    public abstract class Circle implements Shape {

private int radius;

public void draw();

}

E.    public class Circle extends Shape {

private int radius;

public void draw() {/* code here */}

}

F.    public abstract class Circle implements Shape {

private int radius;

public void draw() {/* code here */}

}

 

Correct Answer: BE Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 7

Given:

 

public class Barn {

public static void main(String[] args) {

new Barn().go("hi", 1);

new Barn().go("hi", "world", 2);

}

 

public void go(String... y, int x) { System.out.print(y[y.length - 1] + " ");

}

}

 

What is the result?

 

A.    hi hi

B.    hi world

C.    world world

D.    Compilation fails.

E.    An exception is thrown at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

The method go(String[], int) in the type Barn is not applicable for the arguments (String,  int)


 

The variable argument type String of the method go must be the last parameter

 

QUESTION 8

Given:

 

class Nav{

public enum Direction { NORTH, SOUTH, EAST, WEST }

}

 

public class Sprite{

// insert code here

}

 

Which code, inserted at line 14, allows the Sprite class to compile?

 

A.    Direction d = NORTH;

B.    Nav.Direction d = NORTH;

C.    Direction d = Direction.NORTH;

D.    Nav.Direction d = Nav.Direction.NORTH;

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 9

Which statement is true about the classes and interfaces in the exhibit?

 

1.   public interface A {

2.      public void doSomething(String thing);

03. }

 

1.   public class AImpl implements A {

2.        public void doSomething(String msg) {}

03. }

 

1.   public class B {

2.      public A doit(){

3.             //more code here

04.    }

05.    public String execute(){

06        //more code here 07 }

08. }

 

1.   public class C extends B {

2.      public AImpl doit(){

3.             //more code here

04.       } 05.

6.        public Object execute() {

7.             //more code here

08.    }

09. }

 

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.


 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

The return type is incompatible with B.execute()

 

QUESTION 10

What is the result?

 

11.  public class Person {

12.      String name = "No name";

13.      public Person(String nm) { name = nm; }

14. } 15.

16.  public class Employee extends Person {

17.      String empID = "0000";

18.      public Employee(String id) { empID = id; }

19. } 20.

21.  public class EmployeeTest {

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

23.            Employee e = new Employee("4321");

24.            System.out.println(e.empID);

25.    }

26. }

 

        A.  4321

      B.  0000

C.    An exception is thrown at runtime.

D.    Compilation fails because of an error in line 18.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

Implicit super constructor Person() is undefined. Must explicitly invoke another  constructor

 

 


Source from : Oracle.Exactexams.1z0-851.v2013-11-27.by.SomeBody ().pdf

728x90
그리드형(광고전용)

'Certificate > OCAJP' 카테고리의 다른 글

[1Z0-851B] Question 11~20  (0) 2017.08.11
[1Z0-851B] Question 01~10  (0) 2017.08.11
[1Z0-851A] Question 51~60  (0) 2017.08.05
[1Z0-851A] Question 41~50  (0) 2017.08.05
[1Z0-851A] Question 31~40  (0) 2017.08.05
[1Z0-851A] Question 21~30  (0) 2017.08.05
[1Z0-851A] Question 11~20  (0) 2017.08.05
OCJP Dumps  (0) 2017.07.12
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖