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

QUESTION 11

Given:

 

1.    public class TestOne {

2.                 public static void main (String[] args) throws Exception {

3.                               Thread.sleep(3000);

4.                               System.out.println("sleep");

5.          }

6.  }

What is the result?

 

A.    Compilation fails.

B.    An exception is thrown at runtime.

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

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

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:


 

QUESTION 12

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?

 

A.    Compilation fails.

B.    An exception is thrown at runtime.

C.    The code executes and prints "running".

D.    The code executes and prints "runningrunning".

E.    The code executes and prints "runningrunningrunning".

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 13

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


 

A.    declare reset() using the synchronized keyword

B.    declare getName() using the synchronized keyword

C.    declare getCount() using the synchronized keyword

D.    declare the constructor using the synchronized keyword

E.    declare increment() using the synchronized keyword

 

Correct Answer: ACE Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 14

Given that Triangle implements Runnable, and:

 

void go() throws Exception {

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

for(int x = 1; x < 100000; x++) {

//insert code here line 35

if(x%100 == 0) System.out.print("g");

}

}

 

public void run() {

try {

for(int x = 1; x < 100000; x++) {

// insert the same code here line 41

if(x%100 == 0) System.out.print("t");

}

} catch (Exception e) {

 

}

}

 

Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute? (Choose two.)

 

A.    Thread.wait();

B.    Thread.join();

C.    Thread.yield();

D.    Thread.sleep(1);

E.    Thread.notify();

 

Correct Answer: CD Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 15

Given:

 

public class Yikes {

 

public static void go(Long n) { System.out.print("Long ");


 

}

 

public static void go(Short n) { System.out.print("Short ");

}

 

public static void go(int n) { System.out.print("int ");

}

 

public static void main(String[] args) {

short y = 6; long z = 7; go(y);

go(z);

}

}

 

What is the result?

 

A.    int Long

B.    Short Long

C.    Compilation fails.

D.    An exception is thrown at runtime.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 16

Given:

 

12.  Date date = new Date();

13.  df.setLocale(Locale.ITALY);

14.  String s = df.format(date);

 

The variable df is an object of type DateFormat that has been initialized in line 11. What is the result if this code is run on December 14, 2000?

 

A.    The value of s is 14-dic-2000.

B.    The value of s is Dec 14, 2000.

C.    An exception is thrown at runtime.

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

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

The method setLocale(Locale) is undefined for the type DateFormat. It should be done in line 11 like this

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ITALY);

 

 

QUESTION 17

Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)

 

A.    When using versions of Java technology earlier than 5.0.

B.    When sharing a StringBuffer among multiple threads.

C.    When using the java.io class StringBufferInputStream.

D.    When you plan to reuse the StringBuffer to build more than one string.

 

Correct Answer: AB Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 18

Given that c is a reference to a valid java.io.Console object,  and:

 

11.  String pw = c.readPassword("%s", "pw: ");

12.  System.out.println("got " + pw);

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

14.  System.out.println(" got ", name);

 

If the user types fido when prompted for a password, and then responds bob when prompted for a name, what is the result?

 

A.    pw: got fido name: bob got bob

B.    pw: fido got fido name: bob got bob

C.    pw: got fido name: bob got bob

D.    pw: fido got fido name: bob got bob

E.    Compilation fails.

F.    An exception is thrown at runtime.

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

There are two compilation errors:

line 11: Type mismatch: cannot convert from char[] to  String

line 14: The method println(String) in the type PrintStream is not applicable for the arguments (String, String)

 

 

QUESTION 19

Given:

 

11.  String test = "This is a test";

12.  String[] tokens = test.split("\s");

13.  System.out.println(tokens.length);

 

What is the result?

 

A.    0

B.    1

C.    4

D.    Compilation fails.

E.    An exception is thrown at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:


 

line 12: Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ) You have to add another "\" to correctly escape it.

 

 

QUESTION 20

Given:

 

import java.io.*;

 

class Animal { Animal() {

System.out.print("a");

}

}

 

class Dog extends Animal implements Serializable { Dog() {

System.out.print("d");

}

}

 

public class Beagle extends Dog {

}

 

If an instance of class Beagle is created, then Serialized, then deSerialized, what is the result?

 

A.    ad

B.    ada

C.    add

D.    adad

E.    Compilation fails.

F.    An exception is thrown at runtime.

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

 

 


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

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

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

[1Z0-851E] Question 01~10  (0) 2017.08.15
[1Z0-851D] Question 41~50  (0) 2017.08.13
[1Z0-851D] Question 31~40  (0) 2017.08.13
[1Z0-851D] Question 21~30  (0) 2017.08.13
[1Z0-851D] Question 01~10  (0) 2017.08.13
[1Z0-851C] Question 51~60  (0) 2017.08.12
[1Z0-851C] Question 41~50  (0) 2017.08.12
[1Z0-851C] Question 31~40  (0) 2017.08.12
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖