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

QUESTION 21

Given:

 

1.    public class TestFive {

2.                 private int x;

3.

4.                 public void foo() {

5.                               int current = x;

6.                               x = current + 1;

7.          }

8.

9.          public void go() {

10.                for(int i = 0; i < 5; i++) {

11.                                         new Thread() {

12.                                                      public void run() {

13.                                                                    foo();

14.                                                                    System.out.print(x + ", ");

15.                                }

16.                        }.start();

17.                }

18.        }

19. }

Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ? (Choose two.)

 

A.    move the line 14 print statement into the foo() method

B.    change line 9 to public synchronized void go() {

C.    change the variable declaration on line 2 to private volatile int  x;

D.    wrap the code inside the foo() method with a synchronized( this ) block

E.    wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }

 

Correct Answer: AD Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 22

Given that t1 is a reference to a live thread, which is true?


A.    The Thread.sleep() method can take t1 as an argument.

B.    The Object.notify() method can take t1 as an argument.

C.    The Thread.yield() method can take t1 as an argument.

D.    The Thread.setPriority() method can take t1 as an argument.

E.    The Object.notify() method arbitrarily chooses which thread to notify.

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 23

Given:

 

Runnable r = new Runnable() {

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

}

};

 

Thread t = new Thread(r) {

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

}

};

 

t.start();

 

What is the result?

 

A.    Cat

B.    Dog

C.    Compilation fails.

D.    The code runs with no output.

E.    An exception is thrown at runtime.

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 24

Given:

 

public class Threads5 {

public static void main (String[] args) {

new Thread(new Runnable() {

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

}}).start();

}

}

 

What is the result?


A.    Compilation fails.

B.    An exception is thrown at runtime.

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

D.    The code executes normally, but nothing prints.

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 25

Given:

 

9.   class One {

10.      void foo() { }

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

 

A.    int foo() { /* more code here */ }

B.    void foo() { /* more code here */ }

C.    public void foo() { /* more code here */ }

D.    private void foo() { /* more code here */ }

E.    protected void foo() { /* more code here */ }

 

Correct Answer: BCE Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 26

Given:

 

8.   abstract public class Employee {

9.        protected abstract double getSalesAmount(); 10.

11.      public double getCommision() {

12.            return getSalesAmount() * 0.15;

13.    }

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; }


Correct Answer: BD Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 27

Given:

 

1.    class X {

2.                 X() { System.out.print(1); }

3.

4.                 X(int x) {

5.                               this(); System.out.print(2);

6.          }

7.  }

8.

9.    public class Y extends X {

10.              Y() { super(6); System.out.print(3); }

11. 

12.              Y(int y) {

13.                            this(); System.out.println(4);

14.        }

15.

16.        public static void main(String[] a) { new Y(5); }

17. }

What is the result?

 

A.   13

B. 134

C. 1234

D. 2134

E. 2143

F. 4321

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 28

Given:

 

package com.sun.scjp;

 

public class Geodetics {

public static final double DIAMETER = 12756.32; // kilometers

}

 

Which two correctly access the DIAMETER member of the Geodetics class? (Choose two.)

 

A.    import com.sun.scjp.Geodetics;

public class TerraCarta {

public double halfway() { return Geodetics.DIAMETER/2.0; }

}

B.    import static com.sun.scjp.Geodetics;

public class TerraCarta{

public double halfway() { return DIAMETER/2.0; }

}

C.    import static com.sun.scjp.Geodetics.*;

public class TerraCarta {

public double halfway() { return DIAMETER/2.0; }

}

D.    package com.sun.scjp;

public class TerraCarta {

public double halfway() { return DIAMETER/2.0; }

}

 

Correct Answer: AC Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 29

Given:

 

1.    public class A {

2.                 public void doit() {

3.          }

4.

5.                 public String doit() {

6.                               return "a";

7.          }

8.

9.                 public double doit(int x) {

10.                            return 1.0;

11.        }

12. }

What is the result?

 

A.    An exception is thrown at runtime.

B.    Compilation fails because of an error in line 9.

C.    Compilation fails because of an error in line 5.

D.    Compilation succeeds and no runtime errors with class A occur.

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 30

Given:

 

35.  String #name = "Jane Doe";

36.  int $age = 24;

37.  Double _height = 123.5;

38.  double ~temp = 37.5;


Which two statements are true? (Choose two.)

 

A.    Line 35 will not compile.

B.    Line 36 will not compile.

C.    Line 37 will not compile.

D.    Line 38 will not compile.

 

Correct Answer: AD Section: All Explanation

 

Explanation/Reference:

 

 

 


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

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

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

[1Z0-851C] Question 01~10  (0) 2017.08.12
[1Z0-851B] Question 51~60  (0) 2017.08.11
[1Z0-851B] Question 41~50  (0) 2017.08.11
[1Z0-851B] Question 31~40  (0) 2017.08.11
[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
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖