2016년 8월 14일 일요일

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

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

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

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

그럼 시작.
QUESTION 1
A company that makes Computer Assisted Design (CAD) software has, within its application, some utility classes that are used to perform 3D rendering tasks. The company's chief scientist has just improved the performance of one of the utility classes' key rendering algorithms, and has assigned a programmer to replace the old algorithm with the new algorithm. When the programmer begins researching the utility classes, she is happy to discover that the algorithm to be replaced exists in only one class. The programmer reviews that class's API, and replaces the old algorithm with the new algorithm, being careful that her changes adhere strictly to the class's API. Once testing has begun, the programmer discovers that other classes that use the class she changed are no longer working properly. What design flaw is most likely the cause of these new bugs?

A. Inheritance
: 상속
B. Tight coupling
: 강한 결합
C. Low cohesion
: 약한 응집력
D. High cohesion
: 강한 응집력
E. Loose coupling
: 약한 결합
F. Object immutability
: 객체 불변

Answer: B


QUESTION 2
Given:

1. class ClassA {
2.     public int numberOfInstances;
3.     protected ClassA(int numberOfInstances) {
4.         this.numberOfInstances = numberOfInstances;
5.     }
6. }
7. public class ExtendedA extends ClassA {
8.     private ExtendedA(int numberOfInstances) {
9.         super(numberOfInstances);
10.     }
11.     public static void main(String[] args) {
12.         ExtendedA ext = new ExtendedA(420);
13.         System.out.print(ext.numberOfInstances);
14.     }
15. }

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

A. 420 is the output.
B. An exception is thrown at runtime.
C. All constructors must be declared public.
D. Constructors CANNOT use the private modifier.
E. Constructors CANNOT use the protected modifier.

Answer: A


QUESTION 3
Given:
class ClassA {}
class ClassB extends ClassA {}
class ClassC extends ClassA {}
and:
ClassA p0 = new ClassA();
ClassB p1 = new ClassB();
ClassC p2 = new ClassC();
ClassA p3 = new ClassB();
ClassA p4 = new ClassC();

Which three are valid? (Choose three.)
: 옳은 거 3개는? (3개를 고르시오.)

A. p0 = p1;
B. p1 = p2;
C. p2 = p4;
D. p2 = (ClassC)p1;
E. p1 = (ClassB)p3;
F. p2 = (ClassC)p4;

Answer: AEF


QUESTION 4
Given:
class Thingy { Meter m = new Meter(); }
class Component { void go() { System.out.print("c"); } }
class Meter extends Component { void go() { System.out.print("m"); } } 8.
class DeluxeThingy extends Thingy {
public static void main(String[] args) {
DeluxeThingy dt = new DeluxeThingy();        
dt.m.go();        
Thingy t = new DeluxeThingy();        
t.m.go();    
}
}

Which two are true? (Choose two.)
: 두 개의 사실은? (2개를 고르시오.)

A. The output is mm.
B. The output is mc.
C. Component is-a Meter.
D. Component has-a Meter.
E. DeluxeThingy is-a Component.
F. DeluxeThingy has-a Component.

Answer: AF


QUESTION 5
Given:

10. interface Jumper { public void jump(); }
...
20. class Animal {}
...
30. class Dog extends Animal {
31. Tail tail;
32. }
...
40. class Beagle extends Dog implements Jumper{
41. public void jump() {}
42. }
...
50. class Cat implements Jumper{
51.     public void jump() {}
52. }

Which three are true? (Choose three.)
: 3개의 사실은? (3개를 고르시오.)

A. Cat is-a Animal
B. Cat is-a Jumper
C. Dog is-a Animal
D. Dog is-a Jumper
E. Cat has-a Animal
F. Beagle has-a Tail
G. Beagle has-a Jumper

Answer: BCF


QUESTION 6
Given:

1. import java.util.*;
2. public class WrappedString {
3.     private String s;
4.     public WrappedString(String s) { this.s = s; }
5.     public static void main(String[] args) {
6.         HashSet<Object> hs = new HashSet<Object>();
7.         WrappedString ws1 = new WrappedString("aardvark");
8.         WrappedString ws2 = new WrappedString("aardvark");
9.         String s1 = new String("aardvark");
10.         String s2 = new String("aardvark");
11.         hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2);
12.         System.out.println(hs.size()); } }

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

A. 0
B. 1
C. 2
D. 3
E. 4
F. Compilation fails.
G. An exception is thrown at runtime.

Answer: D


QUESTION 7
Given:

3. import java.util.*;
4. public class G1 {
5.    public void takeList(List<? extends String> list) {
6. //        insert code here
7.     }
8. }

Which three code fragments, inserted independently at line 6, will compile? (Choose three.)
: 6라인에서 독립적으로 삽입할 때, 컴파일이 되는 3가지 코드 조각은? (3개를 고르시오.)

A. list.add("foo");
B. Object o = list;
C. String s = list.get(0);
D. list = new ArrayList<String>();
E. list = new ArrayList<Object>();

Answer: BCD


QUESTION 8
Given that the elements of a PriorityQueue are ordered according to natural ordering, and:

import java.util.*;
public class GetInLine {
     public static void main(String[] args) {
PriorityQueue<String> pq = new PriorityQueue<String>();        
pq.add("banana");        
pq.add("pear");        
pq.add("apple");        
System.out.println(pq.poll() + " " + pq.peek());    
}
}

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

A. apple pear
B. banana pear
C. apple apple
D. apple banana
E. banana banana

Answer: D


QUESTION 9
Given:

enum Example { ONE, TWO, THREE }
Which statement is true?
: 어느 문장이 사실인가?

A. The expressions (ONE == ONE) and ONE.equals(ONE) are both guaranteed to be true.
B. The expression (ONE < TWO) is guaranteed to be true and ONE.compareTo(TWO) is guaranteed to be less than one.
C. The Example values cannot be used in a raw java.util.HashMap; instead, the programmer must use a java.util.EnumMap.
D. The Example values can be used in a java.util.SortedSet, but the set will NOT be sorted because enumerated types do NOT implement java.lang.Comparable.

Answer: A


QUESTION 10
Given:

import java.util.*;
public class Mapit {    
public static void main(String[] args) {        
Set<Integer> set = new HashSet<Integer>();        
Integer i1 = 45;        
Integer i2 = 46;        
set.add(i1);        
set.add(i1);
        set.add(i2); System.out.print(set.size() + " ");        
set.remove(i1); System.out.print(set.size() + " ");        
i2 = 47;        
set.remove(i2); System.out.print(set.size() + " ");    
}
}
What is the result?
: 결과는 무엇인가?

A. 2 1 0
B. 2 1 1
C. 3 2 1
D. 3 2 2
E. Compilation fails.
F. An exception is thrown at runtime.

Answer: B


QUESTION 11
Given:

import java.util.*;
public class Explorer1 {    
public static void main(String[] args) {        
TreeSet<Integer> s = new TreeSet<Integer>();        
TreeSet<Integer> subs = new TreeSet<Integer>();        
for(int i = 606; i < 613; i++)            
f(i%2 == 0) s.add(i);        
subs = (TreeSet)s.subSet(608, true, 611, true);        
s.add(609);        
System.out.println(s + " " + subs);    
}
}

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

A. Compilation fails.
B. An exception is thrown at runtime.
C. [608, 609, 610, 612] [608, 610]
D. [608, 609, 610, 612] [608, 609, 610]
E. [606, 608, 609, 610, 612] [608, 610]
F. [606, 608, 609, 610, 612] [608, 609, 610]

Answer: F


QUESTION 12
Given:

34. HashMap props = new HashMap();
35. props.put("key45", "some value");
36. props.put("key12", "some other value");
37. props.put("key39", "yet another value");
38. Set s = props.keySet();
39. //insert code here

What, inserted at line 39, will sort the keys in the props HashMap?
: 39라인에 삽입하여, props HashMap 안의 키들이 정렬이 되는 것은 무엇인가?

A. Arrays.sort(s);
B. s = new TreeSet(s);
C. Collections.sort(s);
D. s = new SortedSet(s);

Answer: B


QUESTION 13
Which two statements are true? (Choose two.)
: 어느 두 개의 문장이 사실인가? (2개를 고르시오.)

A. It is possible to synchronize static methods.
: 정적 메소드를 동기화 할 수 있다.
B. When a thread has yielded as a result of yield(), it releases its locks.
C. When a thread is sleeping as a result of sleep(), it releases its locks.
D. The Object.wait() method can be invoked only from a synchronized context.
: Object.wait() 메소드는 동기화 된 context에서 호출 할 수 있다.
E. The Thread.sleep() method can be invoked only from a synchronized context.
F. When the thread scheduler receives a notify() request, and notifies a thread, that thread immediately releases its lock.

Answer: AD


QUESTION 14
Given:
public class TestOne implements Runnable {
     public static void main (String[] args) throws Exception {
Thread t = new Thread(new TestOne());
t.start();        
System.out.print("Started");        
t.join();        
System.out.print("Complete");    
}    
public void run() {
for (int i = 0; i < 4; i++) {            
System.out.print(i);        
}    
}
}

What can be a result?
: 결과는 무엇인가?

A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes and prints StartedComplete
D. The code executes and prints StartedComplete0123
E. The code executes and prints Started0123Complete

Answer: E


QUESTION 15
Which three will compile and run without exception? (Choose three.)
: 예외 없이 컴파일 되고 실행되는 3개는 어느 것인가? (3개를 고르시오.)

A. private synchronized Object o;
B. void go() {
synchronized() { /* code here */ }
C. public synchronized void go() { /* code here */ }
D. private synchronized(this) void go() { /* code here */ }
E. void go() { synchronized(Object.class) { /* code here */ }
F. void go() { Object o = new Object(); synchronized(o) { /* code here */ }

Answer: CEF


QUESTION 16
Given:
1. public class TestFive {
2.     private int x;
3.     public void foo() {
4.         int current = x;
5.         x = current + 1;
6.     }
7.     public void go() {
8.         for(int i = 0; i < 5; i++) {
9.             new Thread() {
10.                 public void run() {
11.                     foo();
12.                     System.out.print(x + ", ");
13.                 } }.start();
14.         } }
15. }

Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ? (Choose two.)
: 1, 2, 3, 4, 5, 결과물이 나오도록 함께 수정할 두 개는 무엇인가?

A. move the line 12 print statement into the foo() method
B. change line 7 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 }

Answer: AD




QUESTION 17
Given that t1 is a reference to a live thread, which is true?
: t1이 live thread를 참조하고 있다고 할 때, 어느 것이 사실인가?
 
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.
 
Answer: E


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

Answer: B


QUESTION 19
Given:

1. public class Threads5 {
2.     public static void main (String[] args) {
3.         new Thread(new Runnable() {
4.             public void run() {
5.                 System.out.print("bar");
6.             }}).start();
7.     }
8. }

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.

Answer: C


QUESTION 20
Given: class One {
     void foo() { }
}
class Two extends One {
14. //    insert method here
}

Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)
: 14라인에 개별적으로 삽입하면, Two 클래스가 올바르게 완료되는 3개 메소드는?

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 */ }

Answer: BCE

이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
apricot
n.명사 살구

insensible
aj.형용사 무감각한

contagious
aj.형용사 (접촉을 통해) 전염되는, 전염성의

survival
n.명사 생존

shoot up
급속히 자라다

댓글 없음:

댓글 쓰기

대항해시대 조선 랭작

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