2016년 8월 14일 일요일

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

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

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

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

그럼 시작.
QUESTION 1
Given:

11. String test = "Test A. Test B. Test C.";
12. // insert code here
13. String[] result = test.split(regex);

Which regular expression, inserted at line 12, correctly splits test into "Test A", "Test B", and "Test C"?
: 12라인에 삽입하여 올바르게 "Test A", "Test B", "Test C" 으로 분할되는 정규 표현식은 어느 것인가?

A. String regex = "";
B. String regex = " ";
C. String regex = ".*";
D. String regex = "\\s";
E. String regex = "\\.\\s*";
F. String regex = "\\w[ \.] +";

Answer: E


QUESTION 2
Given:

1. interface A { public void aMethod(); }
2. interface B { public void bMethod(); }
3. interface C extends A,B { public void cMethod(); }
4. class D implements B {
5.     public void bMethod(){}
6. }
7. class E extends D implements C {
8.     public void aMethod(){}
9.     public void bMethod(){}
10.     public void cMethod(){}
11. }

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

A. Compilation fails because of an error in line 3.
B. Compilation fails because of an error in line 7.
C. Compilation fails because of an error in line 9.
D. If you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.
E. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5. F. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

Answer: F


QUESTION 3
What is the result?

1. public class SimpleCalc {
2.     public int value;
3.     public void calculate() { value += 7; }
4. }

and:

1. public class MultiCalc extends SimpleCalc {
2.     public void calculate() { value -= 3; }
3.     public void calculate(int multiplier) {
4.         calculate();
5.         super.calculate();
6.         value *= multiplier;
7.     }
8.     public static void main(String[] args) {
9.         MultiCalc calculator = new MultiCalc();
10.         calculator.calculate(2);
11.         System.out.println("Value is: " + calculator.value);
12.     }
13. }

A. Value is: 8
B. Compilation fails.
C. Value is: 12
D. Value is: -12
E. The code runs with no output.
F. An exception is thrown at runtime.

Answer: A


QUESTION 4
Given:

1. class Mammal {
2. }
3.
4. class Raccoon extends Mammal {
5.     Mammal m = new Mammal();
6. }
7.
8. class BabyRaccoon extends Mammal {
9. }

Which four statements are true? (Choose four.)
: 사실인 4개의 문장은? (4개를 고르시오.)

A. Raccoon is-a Mammal.
B. Raccoon has-a Mammal.
C. BabyRaccoon is-a Mammal.
D. BabyRaccoon is-a Raccoon.
E. BabyRaccoon has-a Mammal.
F. BabyRaccoon is-a BabyRaccoon.

Answer: ABCF


QUESTION 5
Given:

10. interface A { void x(); }
11. class B implements A { public void x() {} public void y() {} }
12. class C extends B { public void x() {} }

And:

20. java.util.List<A> list = new java.util.ArrayList<A>();
21. list.add(new B());
22. list.add(new C());
23. for (A a : list) {
24.     a.x();
25.     a.y();
26. }

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

A. The code runs with no output.
B. An exception is thrown at runtime.
C. Compilation fails because of an error in line 20.
D. Compilation fails because of an error in line 21.
E. Compilation fails because of an error in line 23.
F. Compilation fails because of an error in line 25.

Answer: F


QUESTION 6
Given:

1.
2. public class Hi {
3.     void m1() { }
4.     protected void m2() { }
5. }
6. class Lois extends Hi {
7. //    insert code here
8. }

Which four code fragments, inserted independently at line 7, will compile? (Choose four.)
: 7라인에 삽입하여, 컴파일되는 4개의 코드 조각은?

A. public void m1() { }
B. protected void m1() { }
C. private void m1() { }
D. void m2() { }
E. public void m2() { }
F. protected void m2() { }
G. private void m2() { }

Answer: ABEF


QUESTION 7
Which four statements are true? (Choose four.)
: 사실인 4개의 코드 조각은? (4개를 고르시오.)

A. Has-a relationships should never be encapsulated.
B. Has-a relationships should be implemented using inheritance.
C. Has-a relationships can be implemented using instance variables.
D. Is-a relationships can be implemented using the extends keyword.
E. Is-a relationships can be implemented using the implements keyword.
F. The relationship between Movie and Actress is an example of an is-a relationship.
G. An array or a collection can be used to implement a one-to-many has-a relationship.

Answer: CDEG


QUESTION 8
Given:

01. public class Hello {
02.    String title;
03.    int value;
04.
05.     public Hello() {
06.         title += " World";
07.     }
08.
09.     public Hello(int value) {
10.         this.value = value;
11.         title = "Hello";
12.         Hello();
13.     }
14. }

and:

Hello c = new Hello(5);
System.out.println(c.title);

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

A. Hello
B. Hello World
C. Compilation fails.
D. Hello World 5
E. The code runs with no output.
F. An exception is thrown at runtime.

Answer: C


QUESTION 9
Given:

1. package geometry;
2.
3. public class Hypotenuse {
4.     public InnerTriangle it = new InnerTriangle();
5.
6.     class InnerTriangle {
7.         public int base;
8.         public int height;
9.     }
10. }

Which statement is true about the class of an object that can reference the variable base?
: 변수 기반을 참조할 수 있는 개체의 클래스에 대한 사실인 문장은?

A. It can be any class.
B. No class has access to base.
C. The class must belong to the geometry package.
D. The class must be a subclass of the class Hypotenuse.
 
Answer: C


QUESTION 10
Click the Exhibit button.

1. public class A {
2.    
3.     private int counter = 0;
4.    
5.     public static int getInstanceCount(){
6.         return counter;
7.     }
8.    
9.     public A(){
10.         counter++;
11.     }
12. }
13.  

Given this code from Class B:

A a1 = new A();
A a2 = new A();
A a3 = new A();
System.out.println(A.getInstanceCount());

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

A. Compilation of class A fails.
B. Line 28 prints the value 3 to System.out.
C. Line 28 prints the value 1 to System.out.
D. A runtime error occurs when line 25 executes.
E. Compilation fails because of an error on line 28.

Answer: A


QUESTION 11
Given:

10. interface Data { public void load(); }
11. abstract class Info { public abstract void load(); }  

Which class correctly uses the Data interface and Info class?
: Data 인터페이스와 Info 클래스를 올바르게 사용한 클래스는?

A. public class Employee extends Info implements Data {
public void load() { /*do something*/ }
 }
B. public class Employee implements Info extends Data {
public void load() { /*do something*/ }
 }
C. public class Employee extends Info implements Data public void
load(){/*do something*/ }
public void Info.load(){ /*do something*/ }
 }
D. public class Employee implements Info extends Data {
public void Data.load(){ /*do something*/ }
public void load(){ /*do something*/ }
 }
E. public class Employee implements Info extends Data {
public void load(){ /*do something*/ }
public void Info.load(){ /*do something*/ }
 }
F. public class Employee extends Info implements Data{
public void Data.load() { /*do something*/ }
public void Info.load() { /*do something*/ }
 }

Answer: A


QUESTION 12
Given:

1. class Alligator {
2.     public static void main(String[] args) {
3.         int[] x[] = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
4.         int[][] y = x;
5.         System.out.println(y[2][1]);
6.     }
7. }

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

A. 2
B. 3
C. 4
D. 6
E. 7
F. Compilation fails.

Answer: E


QUESTION 13
Given:

abstract class C1 {
public C1() { System.out.print(1); }
}
class C2 extends C1 {
public C2() { System.out.print(2); }
}
class C3 extends C2 {
public C3() { System.out.println(3); }
}
public class Ctest {
public static void main(String[] a) { new C3(); }
}

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

A. 3
B. 23
C. 32
D. 123
E. 321
F. Compilation fails.
G. An exception is thrown at runtime.

Answer: D


QUESTION 14
Given:

1. class One {
2.     public One foo() {
3.         return this;
4.     }
5. }
6.
7. class Two extends One {
8.     public One foo() {
9.         return this;
10.     }
11. }
12.
13. class Three extends Two {
14.     // insert method here
15. }

Which two methods, inserted individually, correctly complete the Three class? (Choose two.)
: 개별적으로 삽입하여, Three 클래스가 올바르게 완료되는 2개의 메소드는 무엇인가? (2개를 고르시오.)  
 
A. public void foo() {}
B. public int foo() { return 3; }
C. public Two foo() { return this; }
D. public One foo() { return this; }
E. public Object foo() { return this; }

Answer: CD


QUESTION 15
Which two classes correctly implement both the java.lang.Runnable and the java.lang.Cloneable interfaces? (Choose two.)
: java.lang.Runnable 와 java.lang.Cloneable 인터페이스를 모두 올바르게 구현한 2개의 클래스는? (2개를 고르시오.)

A. public class Session implements Runnable, Cloneable {
     public void run();    
public Object clone();
}
B. public class Session extends Runnable, Cloneable {
     public void run() { /* do something */ }    
public Object clone() { /* make a copy */ }
}
C. public class Session implements Runnable, Cloneable {
     public void run() { /* do something */ }    
public Object clone() { /* make a copy */ }
}
D. public abstract class Session implements Runnable, Cloneable {
     public void run() { /* do something */ }    
public Object clone() { /*make a copy */ }
}
E. public class Session implements Runnable, implements Cloneable {
     public void run() { /* do something */ }    
public Object clone() { /* make a copy */ }
}

Answer: CD


QUESTION 16
Given:

1. class TestA {
2.     public void start() { System.out.println("TestA"); }
3. }
4. public class TestB extends TestA {
5.     public void start() { System.out.println("TestB"); }
6.     public static void main(String[] args) {
7.         ((TestA)new TestB()).start();
8.     }
9. }

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

A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.

Answer: B


QUESTION 17
Given:

11. public static void main(String[] args) {
12.    Object obj = new int[] { 1, 2, 3 };
13.    int[] someArray = (int[])obj;
14.    for (int i : someArray) System.out.print(i + " ");
15. }

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

A. 1 2 3
B. Compilation fails because of an error in line 12.
C. Compilation fails because of an error in line 13.
D. Compilation fails because of an error in line 14.
E. A ClassCastException is thrown at runtime.

Answer: A


QUESTION 18
Click the Exhibit button.

1. public class Threads1 {
2.     int x = 0;
3.     public class Runner implements Runnable {
4.         public void run(){
5.             int current = 0;
6.             for(int i = 0; i<4; i++){
7.                 current = x;
8.                 System.out.println(current + ", ");
9.                 x = current + 2;
10.             }
11.         }
12.     }
13.    
14.     public static void main(String[] args) {
15.         new Threads1().go();
16.     }
17.    
18.     public void go(){
19.         Runnable r1 = new Runner();
20.         new Thread(r1).start();
21.         new Thread(r1).start();
22.     }
23. }

Which two are possible results? (Choose two.)


A. 0, 2, 4, 4, 6, 8, 10, 6,
B. 0, 2, 4, 6, 8, 10, 2, 4,
C. 0, 2, 4, 6, 8, 10, 12, 14,
D. 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,
E. 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,

Answer: AC


QUESTION 19
Given:

foo and bar are public references available to many other threads. foo refers to a Thread and bar is an Object.  The thread foo is currently executing bar.wait(). From another thread, what provides the most reliable way to ensure that foo will stop executing wait()?

A. foo.notify();
B. bar.notify();
C. foo.notifyAll();
D. Thread.notify();
E. bar.notifyAll();
F. Object.notify();

Answer: E


QUESTION 20
Given:

public class PingPong implements Runnable {
synchronized void hit(long n) {
for (int i = 1; i < 3; i++)
System.out.print(n + "-" + i + " ");
}
    public static void main(String[] args) {
new Thread(new PingPong()).start();
new Thread(new PingPong()).start();
}

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

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

A. The output could be 8-1 7-2 8-2 7-1
B. The output could be 7-1 7-2 8-1 6-1
C. The output could be 8-1 7-1 7-2 8-2
D. The output could be 8-1 8-2 7-1 7-2
 
Answer: CD

이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
grotesque
aj.형용사 터무니없는, 말도 안 되는

criticize
v.동사 비판하다

weighty
aj.형용사 중대한

languish
v.동사 (강요를 받아 어디에서) 머물다; (오랫동안 불쾌한 일을) 겪다

feel about
여기저기 더듬어 찾다

댓글 없음:

댓글 쓰기

대항해시대 조선 랭작

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