2016년 8월 14일 일요일

OCJP - 1Z0-851(D-1) 공부하자!

Name : OCJP Study
Category : Software
Purpose : JAVA 공부하면서 OCJP 가 합격이 되도록 비나이다.
compatibility : ...
Etc : eclipse

공부한 거는 Post 하자.!!!

JAVA도 공부하면서 OCJP 도 한번에 합격하시기를...
지금 이글을 읽을 정도로 자신의 시간을 투자하는 사람이라면 합격은 당연한것인가. 흠.

그럼 시작.
QUESTION 1
Given:

1. public class KungFu {
2.     public static void main(String[] args) {
3.         Integer x = 400;
4.         Integer y = x;
5.         x++;
6.         StringBuilder sb1 = new StringBuilder("123");
7.         StringBuilder sb2 = sb1;
8.         sb1.append("5");
9.         System.out.println((x == y) + " " + (sb1 == sb2));
10.     }
11. }

What is the result?
: 결과는 무엇인가?

A. true true
B. false true
C. true false
D. false false
E. Compilation fails.
F. An exception is thrown at runtime.

Answer: B


QUESTION 2
Given:

11. class Converter {
12.     public static void main(String[] args) {
13.         Integer i = args[0];
14.         int j = 12;
15.         System.out.println("It is " + (j == i) + " that j==i.");
16.     }
17. }

What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?
: 프로그래머가 코드를 컴파일하고 java Converter 로 12를 명형하여 실행하려고 한다면 결과는 무엇인가?

A. It is true that j==i.
B. It is false that j==i.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 13.

Answer: D


QUESTION 3
Click the Exhibit button.

01. public class A {
02.     public String doit(int x, int y){
03.         return "a";
04.     }
05.    
06.     public String doit(int... vals){
07.         return "b";
08.     }
09. }  

Given:

25.  A a = new A();
26.  System.out.println(a.doit(4, 5));
 
What is the result?
: 결과는 무엇인가?

A. Line 26 prints a to System.out.
B. Line 26 prints b to System.out.
C. An exception is thrown at line 26 at runtime.
D. Compilation of class A will fail due to an error in line 6.

Answer: A


QUESTION 4
Given:

1. public class Plant {
2.     private String name;
3.
4.     public Plant(String name) {
5.         this.name = name;
6.     }
7.
8.     public String getName() {
9.         return name;
10.     }
11. }

1. public class Tree extends Plant {
2.     public void growFruit() {
3.     }
4.
5.     public void dropLeaves() {
6.     }
7. }

Which statement is true?
: 사실인 문장은 어느 것인가?

A. The code will compile without changes.
B. The code will compile if public Tree() { Plant(); } is added to the Tree class.
C. The code will compile if public Plant() { Tree(); } is added to the Plant class.
D. The code will compile if public Plant() { this("fern"); } is added to the Plant class.
E. The code will compile if public Plant() { Plant("fern"); } is added to the Plant class.

Answer: D


QUESTION 5
Click the Exhibit button.
 
1. public class GoTest {
2.     public static void main(String[] args) {
3.         Sente a = new Sente(); a.go();
4.         Goban b = new Goban(); b.go();
5.         Stone c = new Stone(); c.go();
6.     }
7. }
8.
9. class Sente implements Go {
10.     public void go(){
11.         System.out.println("go in Sente");
12.     }
13. }
14.
15. class Goban extends Sente {
16.     public void go(){
17.         System.out.println("go in Goban");
18.     }
19.    
20. }
21. class Stone extends Goban implements Go{    
22. }
23.
24. interface Go { public void go(); }

What is the result?
: 결과는 무엇인가?

A. go in Goban go in Sente go in Sente
B. go in Sente go in Sente go in Goban
C. go in Sente go in Goban go in Goban
D. go in Goban go in Goban go in Sente
E. Compilation fails because of an error in line 17.

Answer: C


QUESTION 6
Given:

11. public interface A111 {
12.     String s = "yo";
13.     public void method1();
14. }
15.
16.
17. interface B {}
18.
19.
20. interface C extends A111, B {
21.     public void method1();
22.     public void method1(int x);
23. }

What is the result?
: 결과는 무엇인가?

A. Compilation succeeds.
B. Compilation fails due to multiple errors.
C. Compilation fails due to an error only on line 20.
D. Compilation fails due to an error only on line 21.
E. Compilation fails due to an error only on line 22.
F. Compilation fails due to an error only on line 12.

Answer: A


QUESTION 7
Click the Exhibit button.

10. interface Foo{
11.    int bar();
12. }
13.
14. public class Beta {
15.
16.     class A implements Foo {
17.         public int bar(){ return 1; }
18.     }
19.    
20.     public int fubar(Foo foo){ return foo.bar(); }
21.    
22.     public void testFoo(){
23.
24.         class A implements Foo{
25.             public int bar(){return 2;}
26.         }
27.        
28.         System.out.println(fubar(new A()));
29.     }
30.    
31.     public static void main(String[] args) {
32.         new Beta().testFoo();
33.     }
34. }

Which three statements are true? (Choose three.)
: 사실인 3 문장은 어느 것인가? (3개를 고르시오.)
 
A. Compilation fails.
B. The code compiles and the output is 2.
C. If lines 16, 17 and 18 were removed, compilation would fail.
D. If lines 24, 25 and 26 were removed, compilation would fail.
E. If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.
F. If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.

Answer: BEF


QUESTION 8
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.

Answer: C


QUESTION 9
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.

Answer: E


QUESTION 10
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.)
: 이 클래스를 멀티 스레드에 안전하게 사용하기 위해 적용해야 할 3가지 변화는 무엇인가? (3개를 고르시오.)

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

Answer: ACE


QUESTION 11
Given that Triangle implements Runnable, and:

31.    void go() throws Exception {
32.        Thread t = new Thread(new Triangle());
33.        t.start();
34.        for(int x = 1; x < 100000; x++) {
35.            //insert code here
36.            if(x%100 == 0) System.out.print("g");
37.        } }
38.    public void run() {
39.        try {
40.            for(int x = 1; x < 100000; x++) {
41.                // insert the same code here
42.                if(x%100 == 0) System.out.print("t");
43.            }
44.        } catch (Exception e) {
45.
46.        }
47.    }

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.)
: 35, 41라인에 각가 독립적으로 삽입하여, 두 스레드를 일시적으로 중단하고 다른 스레드가 실행할 수 있도록 하는 2 문장은 어느 것인가?

A. Thread.wait();
B. Thread.join();
C. Thread.yield();
D. Thread.sleep(1);
E. Thread.notify();

Answer: CD


QUESTION 12
Given:

1. public class TestSeven extends Thread {
2.     private static int x;
3.     public synchronized void doThings() {
4.         int current = x;
5.         current++;
6.         x = current;
7.     }
8.     public void run() {
9.         doThings();
10.     }
11. }

Which statement is true?
: 사실인 문장은?

A. Compilation fails.
B. An exception is thrown at runtime.
C. Synchronizing the run() method would make the class thread-safe.
D. The data in variable x are protected from concurrent access problems.
E. Declaring the doThings() method as static would make the class thread-safe.
F. Wrapping the statements within doThings() in a synchronized(new Object()) { } block would make the class thread-safe.

Answer: E


QUESTION 13
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.

Answer: A


QUESTION 14
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.

Answer: D


QUESTION 15
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.

Answer: E


QUESTION 16
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.

Answer: D


QUESTION 17
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?
: Beagle 클래스의 인스턴스를 만든다면, 다음 역 직렬화 한 다음 직렬화 된 결과는 무엇인가?

A. ad
B. ada
C. add
D. adad
E. Compilation fails.
F. An exception is thrown at runtime.

Answer: B


QUESTION 18
A team of programmers is involved in reviewing a proposed design for a new utility class. After some discussion, they realize that the current design allows other classes to access methods in the utility class that should be accessible only to methods within the utility class itself. What design issue has the team discovered?

A. Tight coupling
B. Low cohesion
C. High cohesion
D. Loose coupling
E. Weak encapsulation
F. Strong encapsulation

Answer: E


QUESTION 19
Given a method that must ensure that its parameter is not null:

11. public void someMethod(Object value) {
12. // check for null value
...
20. System.out.println(value.getClass());
21. }

What, inserted at line 12, is the appropriate way to handle a null value?
: 12라인에 삽입하여 null 값을 처리 할 수 있는 적절한 방법은 무엇인가?

A. assert value == null;
B. assert value != null, "value is null";
C. if (value == null) { throw new AssertionException("value is null"); }
D. if (value == null) { throw new IllegalArgumentException("value is null"); }  

Answer: D


QUESTION 20
Given:

1. public class Target {
2.     private int i = 0;
3.     public int addOne() {
4.         return ++i;
5.     }
6. }

And:

1. public class Client {
2.     public static void main(String[] args){
3.         System.out.println(new Target().addOne());
4.     }
5. }

Which change can you make to Target without affecting Client?
: Client 에 영향을 주지 않고 Target을 만들 수 있는 변화는 무엇인가?

A. Line 4 of class Target can be changed to return i++;
B. Line 2 of class Target can be changed to private int i = 1;
C. Line 3 of class Target can be changed to private int addOne(){
D. Line 2 of class Target can be changed to private Integer i = 0;

Answer: D

이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
assent
n.명사 찬성, 승인

scholarship
n.명사 장학금

extraction
n.명사 (어떤 과정을 거쳐) 뽑아냄, 추출

madonna
n.명사 성모 마리아

something like
다소 …을 닮은, 약간 …비슷한[하게]

댓글 없음:

댓글 쓰기

대항해시대 조선 랭작

숙련도 획득 방법 선박 건조, 선박 강화, 전용함 추가시 숙련도 획득 모두 동일한 공식 적용 획득 숙련도 공식 기본 획득 숙련도 ≒ int{건조일수 × 현재랭크 × (0.525)} 이벤트 & 아이템 사용...