Category : Software
Purpose : JAVA 공부하면서 OCJP 가 합격이 되도록 비나이다.
compatibility : ...
Etc : eclipse
공부한 거는 Post 하자.!!!
JAVA도 공부하면서 OCJP 도 한번에 합격하시기를...
지금 이글을 읽을 정도로 자신의 시간을 투자하는 사람이라면 합격은 당연한것인가. 흠.
그럼 시작.
QUESTION 41
Given:
1. public class Test {
2. public enum Dogs {collie, harrier, shepherd};
3. public static void main(String [] args) {
4. Dogs myDog = Dogs.shepherd;
5. switch (myDog) {
6. case collie:
7. System.out.print("collie ");
8. case default:
9. System.out.print("retriever ");
10. case harrier:
11. System.out.print("harrier ");
12. }
13. }
14. }
What is the result?
: 결과는 무엇인가?
A. harrier
B. shepherd
C. retriever
D. Compilation fails.
E. retriever harrier
F. An exception is thrown at runtime.
Answer: D
QUESTION 42
Given:
1. public class Breaker2 {
2. static String o = "";
3.
4. public static void main(String[] args) {
5. z: for (int x = 2; x < 7; x++) {
6. if (x == 3)
7. continue;
8. if (x == 5)
9. break z;
10. o = o + x;
11. }
12. System.out.println(o);
13. }
14. }
What is the result?
: 결과는 무엇인가?
A. 2
B. 24
C. 234
D. 246
E. 2346
F. Compilation fails.
Answer: B
QUESTION 43
Given:
1. public static void main(String[] args) {
2. String str = "null";
3. if (str == null) {
4. System.out.println("null");
5. } else (str.length() == 0) {
6. System.out.println("zero");
7. } else {
8. System.out.println("some");
9. }
10. }
What is the result?
: 결과는 무엇인가?
A. null
B. zero
C. some
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: D
QUESTION 44
Given:
1. import java.io.IOException;
2.
3. class A {
4.
5. public void process() {
6. System.out.print("A,");
7. }
8.
9. }
10.
11.
12. class B extends A {
13.
14. public void process() throws IOException {
15. super.process();
16. System.out.print("B,");
17. throw new IOException();
18. }
19.
20. public static void main(String[] args) {
21. try {
22. new B().process();
23. } catch (IOException e) {
24. System.out.println("Exception");
25. }
26. }
27. }
What is the result?
: 결과는 무엇인가?
A. Exception
B. A,B,Exception
C. Compilation fails because of an error in line 20.
D. Compilation fails because of an error in line 14.
E. A NullPointerException is thrown at runtime.
Answer: D
QUESTION 45
Given:
11. public void genNumbers() {
12. ArrayList numbers = new ArrayList();
13. for(int i = 0; i < 10; i++) {
14. int value = i * ((int) Math.random());
15. Integer intObj = new Integer(value);
16. numbers.add(intObj);
17. }
18. System.out.println(numbers);
19. }
Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection?
: intObj 가 참조 된 객체가 garbage collection의 후보가 되는 최초의 지점을 표시한 라인은 어느 것인가?
A. Line 16
B. Line 17
C. Line 18
D. Line 19
E. The object is NOT a candidate for garbage collection.
Answer: D
QUESTION 46
Given:
1. public class GC {
2. private Object o;
3. private void doSomethingElse(Object obj) { o = obj; }
4. public void doSomething() {
5. Object o = new Object();
6. doSomethingElse(o);
7. o = new Object();
8. doSomethingElse(null);
9. o = null;
10. }
11. }
When the doSomething method is called, after which line does the Object created in line 5 become available for garbage collection?
: doSomething 메서드가 호출 될 때, 후에 5라인에서 만든 객체가 가비지 컬렉션에 사용할 수있게 하는 라인은 어는 것인가?
A. Line 5
B. Line 6
C. Line 7
D. Line 8
E. Line 9
F. Line 10
Answer: D
QUESTION 47
Given:
1. public class Pass2 {
2. public void main(String[] args) {
3. int x = 6;
4. Pass2 p = new Pass2();
5. p.doStuff(x);
6. System.out.print(" main x = " + x);
7. }
8.
9. void doStuff(int x) {
10. System.out.print(" doStuff x = " + x++);
11. }
12. }
And the command-line invocations:
javac Pass2.java
java Pass2 5
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. An exception is thrown at runtime.
C. doStuff x = 6 main x = 6
D. doStuff x = 6 main x = 7
E. doStuff x = 7 main x = 6
F. doStuff x = 7 main x = 7
Answer: B
QUESTION 48
Given:
1. interface DeclareStuff {
2. public static final int EASY = 3;
3.
4. void doStuff(int t);
5. }
6.
7. public class TestDeclare implements DeclareStuff {
8. public static void main(String[] args) {
9. int x = 5;
10. new TestDeclare().doStuff(++x);
11. }
12.
13. void doStuff(int s) {
14. s += EASY + ++s;
15. System.out.println("s " + s);
16. }
17. }
What is the result?
: 결과는 무엇인가?
A. s 14
B. s 16
C. s 10
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: D
QUESTION 49
A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command:
java games.cards.Poker
What allows the user to do this?
: 유저가 이것을 할 수 있도록 한 것은 무엇인가?
A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java
B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/*.jar
C. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar
D. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java
E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/*.jar F. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/Poker.jar
Answer: C
QUESTION 50
Given a correctly compiled class whose source code is:
1. package com.sun.sjcp;
2.
3. public class Commander {
4. public static void main(String[] args) {
5. // more code here
6. }
7. }
Assume that the class file is located in /foo/com/sun/sjcp/, the current directory is /foo/, and that the classpath contains "." (current directory). Which command line correctly runs Commander?
A. java Commander
B. java com.sun.sjcp.Commander
C. java com/sun/sjcp/Commander
D. java -cp com.sun.sjcp Commander
E. java -cp com/sun/sjcp Commander
Answer: B
QUESTION 51
Given:
interface DoStuff2 {
float getRange(int low, int high);
}
interface DoMore {
float getAvg(int a, int b, int c);
}
abstract class DoAbstract implements DoStuff2, DoMore {
}
06. class DoStuff implements DoStuff2 {
07. public float getRange(int x, int y) {
08. return 3.14f;
09. }
10. }
11.
12. interface DoAll extends DoMore {
13. float getAvg(int a, int b, int c, int d);
14. }
What is the result?
: 결과는 무엇인가?
A. The file will compile without error.
B. Compilation fails. Only line 7 contains an error.
C. Compilation fails. Only line 12 contains an error.
D. Compilation fails. Only line 13 contains an error.
E. Compilation fails. Only lines 7 and 12 contain errors.
F. Compilation fails. Only lines 7 and 13 contain errors.
G. Compilation fails. Lines 7, 12, and 13 contain errors.
Answer: A
QUESTION 52
Given:
public class Spock {
public static void main(String[] args) {
Long tail = 2000L;
Long distance = 1999L;
Long story = 1000L;
if ((tail > distance) ^ ((story * 2) == tail))
System.out.print("1");
if ((distance + 1 != tail) ^ ((story * 2) == distance))
System.out.print("2");
}
}
What is the result?
: 결과는 무엇인가?
A. 1
B. 2
C. 12
D. Compilation fails.
E. No output is produced.
F. An exception is thrown at runtime.
Answer: E
QUESTION 53
Given:
class Payload {
private int weight;
public Payload() {
}
public Payload(int w) {
weight = w;
}
public void setWeight(int w) {
weight = w;
}
public String toString() {
return Integer.toString(weight);
}
}
10. public class TestPayload {
11. static void changePayload(Payload p) {
12. /* insert code */
13. }
14.
15. public static void main(String[] args) {
16. Payload p = new Payload(200);
17. p.setWeight(1024);
18. changePayload(p);
19. System.out.println("p is " + p);
20. }
21. }
Which code fragment, inserted at the end of line 12, produces the output p is 420?
: 12라인의 끝에 삽입하여 출력 p가 420이 나오도록 하는 코드 조각은 어느 것인가?
A. p.setWeight(420);
B. p.changePayload(420);
C. p = new Payload(420);
D. Payload.setWeight(420);
E. p = Payload.setWeight(420);
Answer: A
QUESTION 54
Given:
class Line {
public class Point {
public int x, y;
}
public Point getPoint() {
return new Point();
}
}
class Triangle {
public Triangle() {
// insert code here
}
}
Which code, inserted at line 16, correctly retrieves a local instance of a Point object?
: 16라인에 삽입하여, Point 객체의 로컬 인스턴스를 올바르게 검색한 코드는 어느 것인가?
A. Point p = Line.getPoint();
B. Line.Point p = Line.getPoint();
C. Point p = (new Line()).getPoint();
D. Line.Point p = (new Line()).getPoint();
Answer: D
QUESTION 55
Given:
84. try {
85. ResourceConnection con = resourceFactory.getConnection();
86. Results r = con.query("GET INFO FROM CUSTOMER");
87. info = r.getData();
88. con.close();
89. } catch (ResourceException re) {
90. errorLog.write(re.getMessage());
91. }
92. return info;
Which statement is true if a ResourceException is thrown on line 86?
: ResourceException이 86라인에서 발생한다면 어느 문장이 사실인가?
A. Line 92 will not execute.
B. The connection will not be retrieved in line 85.
C. The resource connection will not be closed on line 88.
D. The enclosing method will throw an exception to its caller.
Answer: C
QUESTION 56
Given:
11. class X { public void foo() { System.out.print("X "); } }
12.
13. public class SubB extends X {
14. public void foo() throws RuntimeException {
15. super.foo();
16. if (true) throw new RuntimeException();
17. System.out.print("B ");
18. }
19. public static void main(String[] args) {
20. new SubB().foo();
21. }
22. }
What is the result?
: 결과는 무엇인가?
A. X, followed by an Exception.
B. No output, and an Exception is thrown.
C. Compilation fails due to an error on line 14.
D. Compilation fails due to an error on line 16.
E. Compilation fails due to an error on line 17.
F. X, followed by an Exception, followed by B.
Answer: A
QUESTION 57
Which two code fragments correctly create and initialize a static array of int elements? (Choose two.)
: 올바르게 만들고 int 요소의 정적 배열을 초기화한 두 코드 조각은? (2개를 고르시오.)
A. static final int[] a = { 100,200 };
B. static final int[] a; static { a=new int[2]; a[0]=100; a[1]=200; }
C. static final int[] a = new int[2]{ 100,200 };
D. static final int[] a; static void init() { a = new int[3]; a[0]=100; a[1]=200; }
Answer: AB
QUESTION 58
Given:
class Alpha {
public void foo() { System.out.print("Afoo "); }
}
public class Beta extends Alpha {
public void foo() { System.out.print("Bfoo "); }
public static void main(String[] args) {
Alpha a = new Beta();
Beta b = (Beta)a;
a.foo();
b.foo();
}
}
What is the result?
: 결과는 무엇인가?
A. Afoo Afoo
B. Afoo Bfoo
C. Bfoo Afoo
D. Bfoo Bfoo
E. Compilation fails.
F. An exception is thrown at runtime.
Answer: D
QUESTION 59
Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object?
(Choose two.)
: StringBuilder 개체와 StringBuffer 개체를 바꿀 때 안전하지 않은 2가지 시나리오는?
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.
Answer: AB
이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
critic
n.명사 비평가, 평론가
unseen
aj.형용사 눈에 보이지 않는
thorny
aj.형용사 (문제 등이) 곤란한
likewise
av.부사 똑같이; 비슷하게
get there
(어떤 장소에) 도착하다
Today.
critic
n.명사 비평가, 평론가
unseen
aj.형용사 눈에 보이지 않는
thorny
aj.형용사 (문제 등이) 곤란한
likewise
av.부사 똑같이; 비슷하게
get there
(어떤 장소에) 도착하다
댓글 없음:
댓글 쓰기