Name : OCJP Study
Category : Software
Purpose : JAVA 공부하면서 OCJP 가 합격이 되도록 비나이다.
compatibility : ...
Etc : eclipse
공부한 거는 Post 하자.!!!
JAVA도 공부하면서 OCJP 도 한번에 합격하시기를...
지금 이글을 읽을 정도로 자신의 시간을 투자하는 사람이라면 합격은 당연한것인가. 흠.
그럼 시작.
QUESTION 21
Click the Exhibit button.
class Computation extends Thread {
private int num;
private boolean isComplete;
private int result;
public Computation(int num){ this.num = num; }
public synchronized void run() {
result = num * 2;
isComplete = true;
notify();
}
public synchronized int getResult() {
while ( ! isComplete ){
try {
wait();
} catch (InterruptedException e) {}
}
return result;
}
public static void main(String[] args) {
Computation[] computations = new Computation[4];
for (int i = 0; i < computations.length; i++) {
computations[i] = new Computation(i);
computations[i].start();
}
for (Computation c : computations) {
System.out.println(c.getResult() + " ");
}
}
}
What is the result?
: 결과는 무엇인가?
A. The code will deadlock.
B. The code may run with no output.
C. An exception is thrown at runtime.
D. The code may run with output "0 6".
E. The code may run with output "2 0 6 4".
F. The code may run with output "0 2 4 6".
Answer: F
QUESTION 22
Which two code fragments will execute the method doStuff() in a separate thread? (Choose two.)
: 별도의 스레드에서 doStuff() 메소드를 실행하는 코드 조각 2개는? (2개를 고르시요.)
A. new Thread() {
public void run() { doStuff(); } };
B. new Thread() {
public void start() { doStuff(); } };
C. new Thread() {
public void start() { doStuff(); } }.run();
D. new Thread() {
public void run() { doStuff(); } }.start();
E. new Thread(new Runnable() {
public void run() { doStuff(); } }).run();
F. new Thread(new Runnable() {
public void run() { doStuff(); } }).start();
Answer: DF
QUESTION 23
Given:
public class Person {
private String name;
public Person(String name) {
this.name = name;
}
public boolean equals(Object o) {
if ( ! ( o instanceof Person) ) return false;
Person p = (Person) o;
return p.name.equals(this.name);
}
}
Which statement is true?
: 사실인 문장은?
A. Compilation fails because the hashCode method is not overridden.
B. A HashSet could contain multiple Person objects with the same name.
C. All Person objects will have the same hash code because the hashCode method is not overridden.
D. If a HashSet contains more than one Person object with name="Fred", then removing another Person, also with name="Fred", will remove them all.
Answer: B
QUESTION 24
Given:
import java.util.*;
public class SortOf {
public static void main(String[] args) {
ArrayList<Integer> a = new ArrayList<Integer>();
a.add(1); a.add(5); a.add(3);
Collections.sort(a);
a.add(2);
Collections.reverse(a);
System.out.println(a);
}
}
What is the result?
: 결과는 무엇인가?
A. [1, 2, 3, 5]
B. [2, 1, 3, 5]
C. [2, 5, 3, 1]
D. [5, 3, 2, 1]
E. [1, 3, 5, 2]
F. Compilation fails.
G. An exception is thrown at runtime.
Answer: C
QUESTION 25
Given:
public class Person {
private name;
public Person(String name) {
this.name = name;
}
public int hashCode() {
return 420;
}
}
Which statement is true?
: 사실인 문장은?
A. The time to find the value from HashMap with a Person key depends on the size of the map.
B. Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.
C. Inserting a second Person object into a HashSet will cause the first Person object to be removed as a duplicate.
D. The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.
Answer: A
QUESTION 26
Given:
public class Drink implements Comparable {
public String name;
public int compareTo(Object o) {
return 0;
}
}
and:
Drink one = new Drink();
Drink two = new Drink();
one.name= "Coffee";
two.name= "Tea";
TreeSet set = new TreeSet();
set.add(one);
set.add(two);
A programmer iterates over the TreeSet and prints the name of each Drink object.
What is the result?
: 한 프로그래머가 TreeSet을 처음부터 끝까지 반복하고 각 Drink 개체의 이름을 출력한다.
결과는 무엇인가?
A. Tea
B. Coffee
C. Coffee
Tea
D. Compilation fails.
E. The code runs with no output.
F. An exception is thrown at runtime.
Answer: B
QUESTION 27
A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?
A. class MinMax<E extends Comparable<E>> {
E min = null;
E max = null;
public MinMax() {}
public void put(E value) { /* store min or max */ }
B. class MinMax<E implements Comparable<E>> {
E min = null;
E max = null;
public MinMax() {}
public void put(E value) { /* store min or max */ }
C. class MinMax<E extends Comparable<E>> {
<E> E min = null;
<E> E max = null;
public MinMax() {}
public <E> void put(E value) { /* store min or max */ }
D. class MinMax<E implements Comparable<E>> {
<E> E min = null;
<E> E max = null;
public MinMax() {}
public <E> void put(E value) { /* store min or max */ }
Answer: A
QUESTION 28
Given:
1. import java.util.*;
2. public class Example {
3. public static void main(String[] args) {
4. // insert code here
5. set.add(new Integer(2));
6. set.add(new Integer(1));
7. System.out.println(set);
8. }
9. }
Which code, inserted at line 4, guarantees that this program will output [1, 2]?
: 4라인에 삽입하여, 이 프로그램에서 [1, 2] 출력이 나오도록 하는 코드는?
A. Set set = new TreeSet();
B. Set set = new HashSet();
C. Set set = new SortedSet();
D. List set = new SortedList();
E. Set set = new LinkedHashSet();
Answer: A
QUESTION 29
Given:
05. class A {
06. void foo() throws Exception { throw new Exception(); }
07. }
08. class SubB2 extends A {
09. void foo() { System.out.println("B "); }
10. }
11. class Tester {
12. public static void main(String[] args) {
13. A a = new SubB2();
14. a.foo();
15. }
16. }
What is the result?
: 결과는 무엇인가?
A. B
B. B, followed by an Exception.
C. Compilation fails due to an error on line 9.
D. Compilation fails due to an error on line 14.
E. An Exception is thrown with no other output.
Answer: D
QUESTION 30
Given:
1. public class Breaker {
2. static String o = "";
3.
4. public static void main(String[] args) {
5. z: o = o + 2;
6. for (int x = 3; x < 8; x++) {
7. if (x == 4)
8. break;
9. if (x == 6)
10. break z;
11. o = o + x;
12. }
13. System.out.println(o);
14. }
15. }
What is the result?
: 결과는 무엇인가?
A. 23
B. 234
C. 235
D. 2345
E. 2357
F. 23457
G. Compilation fails.
Answer: G
QUESTION 31
Given:
11. public void go(int x) {
12. assert (x > 0);
13. switch(x) {
14. case 2: ;
15. default: assert false;
16. }
17. }
18. private void go2(int x) { assert (x < 0); }
Which statement is true?
: 사실인 문장은?
A. All of the assert statements are used appropriately.
B. Only the assert statement on line 12 is used appropriately.
C. Only the assert statement on line 15 is used appropriately.
D. Only the assert statement on line 18 is used appropriately.
E. Only the assert statements on lines 12 and 15 are used appropriately.
F. Only the assert statements on lines 12 and 18 are used appropriately.
G. Only the assert statements on lines 15 and 18 are used appropriately.
Answer: G
QUESTION 32
Given:
1. public static void main(String[] args) {
2. try {
3. args = null;
4. args[0] = "test";
5. System.out.println(args[0]);
6. } catch (Exception ex) {
7. System.out.println("Exception");
8. } catch (NullPointerException npe) {
9. System.out.println("NullPointerException");
10. }
11. }
What is the result?
: 결과는 무엇인가?
A. test
B. Exception
C. Compilation fails.
D. NullPointerException
Answer: C
QUESTION 33
Given:
1. public static void main(String[] args) {
2. for (int i = 0; i <= 10; i++) {
3. if (i > 6) break;
4. }
5. System.out.println(i);
6. }
What is the result?
: 결과는 무엇인가?
A. 6
B. 7
C. 10
D. 11
E. Compilation fails.
F. An exception is thrown at runtime.
Answer: E
QUESTION 34
Given:
11. public void testIfA() {
12. if (testIfB("True")) {
13. System.out.println("True");
14. } else {
15. System.out.println("Not true");
16. }
17. }
18. public Boolean testIfB(String str) {
19. return Boolean.valueOf(str);
20. }
What is the result when method testIfA is invoked?
: testIfA 메소드가 호출될 때, 결과는 무엇인가?
A. True
B. Not true
C. An exception is thrown at runtime.
D. Compilation fails because of an error at line 12.
E. Compilation fails because of an error at line 19.
Answer: A
QUESTION 35
Which can appropriately be thrown by a programmer using Java SE technology to create a desktop application?
A. ClassCastException
B. NullPointerException
C. NoClassDefFoundError
D. NumberFormatException
E. ArrayIndexOutOfBoundsException
Answer: D
QUESTION 36
Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)
A. int []x = {1,2,3,4,5};
for(int y = 0; y < 6; y++)
System.out.println(x[y]);
B. static int[] x = {7,6,5,4};
static { x[1] = 8; x[4] = 3; }
C. for(int y = 10; y < 10; y++)
doStuff(y);
D. void doOne(int x) { doTwo(x); }
void doTwo(int y) { doThree(y); }
void doThree(int z) { doTwo(z); }
E. for(int x = 0; x < 1000000000; x++)
doStuff(x);
F. void counter(int i) { counter(++i); }
Answer: DF
QUESTION 37
Given:
04. public class Tahiti {
05. Tahiti t;
06.
07. public static void main(String[] args) {
08. Tahiti t = new Tahiti();
09. Tahiti t2 = t.go(t);
10. t2 = null;
11. // more code here
12. }
13.
14. Tahiti go(Tahiti t) {
15. Tahiti t1 = new Tahiti();
16. Tahiti t2 = new Tahiti();
17. t1.t = t2;
18. t2.t = t1;
19. t.t = t2;
20. return t1;
21. }
22. }
When line 11 is reached, how many objects are eligible for garbage collection?
: 11라인에 도달했을 때, garbage collection을 받는 개체는 몇 개인가?
A. 0
B. 1
C. 2
D. 3
E. Compilation fails.
Answer: A
QUESTION 38
Given:
interface Animal {
void makeNoise();
}
class Horse implements Animal {
Long weight = 1200L;
public void makeNoise() {
System.out.println("whinny");
}
}
01. public class Icelandic extends Horse {
02. public void makeNoise() {
03. System.out.println("vinny");
04. }
05.
06. public static void main(String[] args) {
07. Icelandic i1 = new Icelandic();
08. Icelandic i2 = new Icelandic();
09. Icelandic i3 = new Icelandic();
10. i3 = i1;
11. i1 = i2;
12. i2 = null;
13. i3 = i1;
14. }
15. }
When line 14 is reached, how many objects are eligible for the garbage collector?
: 14라인에 도달했을 때, garbage collection을 받는 개체는 몇 개인가?
A. 0
B. 1
C. 2
D. 3
E. 4
F. 6
Answer: E
QUESTION 39
Given:
11. public class Commander {
12. public static void main(String[] args) {
13. String myProp = /* insert code here */
14. System.out.println(myProp);
15. }
16. }
and the command line: java -Dprop.custom=gobstopper Commander
Which two, placed on line 13, will produce the output gobstopper? (Choose two.)
: 13라인에 놓아 gobstopper 출력이 생성되는 2개는? (2개를 고르시오.)
A. System.load("prop.custom");
B. System.getenv("prop.custom");
C. System.property("prop.custom");
D. System.getProperty("prop.custom");
E. System.getProperties().getProperty("prop.custom");
Answer: DE
QUESTION 40
Given:
1. public class ItemTest {
2. private final int id;
3.
4. public ItemTest(int id) {
5. this.id = id;
6. }
7.
8. public void updateId(int newId) {
9. id = newId;
10. }
11.
12. public static void main(String[] args) {
13. ItemTest fa = new ItemTest(42);
14. fa.updateId(69);
15. System.out.println(fa.id);
16. }
17. }
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. An exception is thrown at runtime.
C. The attribute id in the ItemTest object remains unchanged.
D. The attribute id in the ItemTest object is modified to the new value.
E. A new ItemTest object is created with the preferred value in the id attribute.
Answer: A
이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
improvement
n.명사 향상
petition
n.명사 진정(서)
upkeep
n.명사 (건물 등의) 유지
lacquer
n.명사 래커(광택제)
and then
그러고는, 그런 다음
댓글 없음:
댓글 쓰기