Name : OCJP Study
Category : Software
Purpose : JAVA 공부하면서 OCJP 가 합격이 되도록 비나이다.
compatibility : ...
Etc : eclipse
공부한 거는 Post 하자.!!!
JAVA도 공부하면서 OCJP 도 한번에 합격하시기를...
지금 이글을 읽을 정도로 자신의 시간을 투자하는 사람이라면 합격은 당연한것인가. 흠.
그럼 시작.
QUESTION 41
Given a pre-generics implementation of a method:
:
11. public static int sum(List list) {
12. int sum = 0;
13. for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
14. int i = ((Integer)iter.next()).intValue();
15. sum += i;
16. }
17. return sum;
18. }
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
:
A. Remove line 14.
B. Replace line 14 with int i = iter.next();
C. Replace line 13 with for (int i : intList) {
D. Replace line 13 with for (Iterator iter : intList) {
E. Replace the method declaration with sum(List<int> intList)
F. Replace the method declaration with sum(List<Integer> intList)
Answer: ACF
QUESTION 42
Given:
23. Object [] myObjects = {
24. new Integer(12),
25. new String("foo"),
26. new Integer(5),
27. new Boolean(true)
28. };
29. Arrays.sort(myObjects);
30. for(int i=0; i<myObjects.length; i++) {
31. System.out.print(myObjects[i].toString());
32. System.out.print(" ");
33. }
What is the result?
: 결과는 무엇인가?
A. Compilation fails due to an error in line 23.
B. Compilation fails due to an error in line 29.
C. A ClassCastException occurs in line 29.
D. A ClassCastException occurs in line 31.
E. The value of all four objects prints in natural order.
Answer: C
QUESTION 43
Given a class Repetition:
: 클래스 반복을 감안할 때
1. package utils;
2.
3. public class Repetition {
4. public static String twice(String s) { return s + s; }
5. }
and given another class Demo:
1. public class Demo {
2. public static void main(String[] args) {
3. System.out.println(twice("pizza"));
4. }
5. }
Which code should be inserted at line 1 of Demo.java to compile and run Demo to print pizzapizza?
:
A. import utils.*;
B. static import utils.*;
C. import utils.Repetition.*;
D. static import utils.Repetition.*;
E. import utils.Repetition.twice();
F. import static utils.Repetition.twice;
G. static import utils.Repetition.twice;
Answer: F
QUESTION 44
A UNIX user named Bob wants to replace his chess program with a new one, but he is not sure where the old one is installed. Bob is currently able to run a Java chess program starting from his home directory /home/bob using the command:
java -classpath /test:/home/bob/downloads/*.jar games.Chess
Bob's CLASSPATH is set (at login time) to:
/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar
What is a possible location for the Chess.class file?
: Chess.class 파일에 대한 가능한 위치는 무엇인가?
A. /test/Chess.class
B. /home/bob/Chess.class
C. /test/games/Chess.class
D. /usr/lib/games/Chess.class
E. /home/bob/games/Chess.class
F. inside jarfile /opt/java/lib/Games.jar (with a correct manifest)
G. inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)
Answer: C
QUESTION 45
Given the following directory structure:
bigProject
|--source
| |--Utils.java
|
|--classes
|--
And the following command line invocation:
: 다음의 명령 라인을 호출 :
javac -d classes source/Utils.java
Assume the current directory is bigProject, what is the result?
: 현재 디렉토리가 bigProject라고 가정한다면, 결과는 무엇인가?
A. If the compile is successful, Utils.class is added to the source directory.
B. The compiler returns an invalid flag error.
C. If the compile is successful, Utils.class is added to the classes directory.
D. If the compile is successful, Utils.class is added to the bigProject directory.
Answer: C
QUESTION 46
Which statement is true?
: 어느 문장이 사실인가?
A. A class's finalize() method CANNOT be invoked explicitly.
: 클래스의 Finalize() 메서드를 명시적으로 호출 할 수 없습니다.
B. super.finalize() is called implicitly by any overriding finalize() method.
: super.finalize )는 어떤 오버라이딩 finalize() 메소드에 의해 암시적으로 호출됩니다.
C. The finalize() method for a given object is called no more than once by the garbage collector.
: 지정된 객체의 finalize() 메소드는 가비지 컬렉터에 의해 두 번 이상 더 이상 호출되지 않습니다.
D. The order in which finalize() is called on two objects is based on the order in which the two objects became finalizable.
: 두 개체에서 호출되는 finalize() 순서는 두 객체가 종료 가능한이되는 순서에 기초한다.
Answer: C
QUESTION 47
Given:
1. public class Batman {
2. int squares = 81;
3. public static void main(String[] args) {
4. new Batman().go();
5. }
6. void go() {
7. incr(++squares);
8. System.out.println(squares);
9. }
10. void incr(int squares) { squares += 10; }
11. }
What is the result?
: 결과는 무엇인가?
A. 81
B. 82
C. 91
D. 92
E. Compilation fails.
F. An exception is thrown at runtime.
Answer: B
QUESTION 48
Given:
public class Yippee {
public static void main(String [] args) {
for(int x = 1; x < args.length; x++) {
System.out.print(args[x] + " ");
}
}
}
and two separate command line invocations:
:
java Yippee
java Yippee 1 2 3 4
What is the result?
: 결과는 무엇인가?
A. No output is produced. 1 2 3
B. No output is produced. 2 3 4
C. No output is produced. 1 2 3 4
D. An exception is thrown at runtime. 1 2 3
E. An exception is thrown at runtime. 2 3 4
F. An exception is thrown at runtime. 1 2 3 4
Answer: B
QUESTION 49
Given:
1. public class Pass {
2. public static void main(String [] args) {
3. int x = 5;
4. Pass p = new Pass();
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. }
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. An exception is thrown at runtime.
C. doStuff x = 6 main x = 6
D. doStuff x = 5 main x = 5
E. doStuff x = 5 main x = 6
F. doStuff x = 6 main x = 5
Answer: D
QUESTION 50
Given:
1. interface Animal { void makeNoise(); }
2. class Horse implements Animal {
3. Long weight = 1200L;
4. public void makeNoise() { System.out.println("whinny"); }
5. }
6.
7. public class Icelandic extends Horse {
8. public void makeNoise() { System.out.println("vinny"); }
9. public static void main(String[] args) {
10. Icelandic i1 = new Icelandic();
11. Icelandic i2 = new Icelandic();
12. Icelandic i3 = new Icelandic();
13. i3 = i1; i1 = i2; i2 = null; i3 = i1;
14. }
15. }
When line 14 is reached, how many objects are eligible for the garbage collector?
: 14라인에 도달하면, 얼마나 많은 개체가 garbage collector을 받는가?
A. 0
B. 1
C. 2
D. 3
E. 4
F. 6
Answer: E
QUESTION 51
Given two files: GrizzlyBear.java and Salmon.java
1. package animals.mammals;
2.
3. public class GrizzlyBear extends Bear {
4. void hunt() {
5. Salmon s = findSalmon();
6. s.consume();
7. }
8. }
1. package animals.fish;
2.
3. public class Salmon extends Fish {
4. public void consume() { /* do stuff */ }
5. }
If both classes are in the correct directories for their packages, and the Mammal class correctly defines the findSalmon() method, which change allows this code to compile?
: 두 클래스는 패키지에 대한 올바른 디렉토리에 있으며, Mammal 클래스는 올바르게 findSalmon() 메소드를 정의합니다,
어떤 변화가 이 코드를 컴파일 할 수 있나?
A. add import animals.mammals.*; at line 2 in Salmon.java
B. add import animals.fish.*; at line 2 in GrizzlyBear.java
C. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.java
D. add import animals.mammals.GrizzlyBear.*; at line 2 in Salmon.java
Answer: B
QUESTION 52
Given:
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0) ? elements[0] : null;
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. An exception is thrown at runtime.
C. The variable first is set to null.
D. The variable first is set to elements[0].
Answer: D
QUESTION 53
A company has a business application that provides its users with many different reports: receivables reports, payables reports, revenue projects, and so on. The company has just purchased some new, state-of-the-art, wireless printers, and a programmer has been assigned the task of enhancing all of the reports to use not only the company's old printers, but the new wireless printers as well. When the programmer starts looking into the application, the programmer discovers that because of the design of the application, it is necessary to make changes to each report to support the new printers.Which two design concepts most likely explain this situation? (Choose two.)
A. Inheritance
B. Low cohesion
C. Tight coupling
D. High cohesion
E. Loose coupling
F. Object immutability
Answer: BC
QUESTION 54
Given:
10. public class SuperCalc {
11. protected static int multiply(int a, int b) { return a * b;}
12. }
and:
20. public class SubCalc extends SuperCalc{
21. public static int multiply(int a, int b) {
22. int c = super.multiply(a, b);
23. return c;
24. }
25. }
and:
30. SubCalc sc = new SubCalc ();
31. System.out.println(sc.multiply(3,4));
32. System.out.println(SubCalc.multiply(2,2));
What is the result?
: 결과는 무엇인가?
A. 12
B. The code runs with no output.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 21.
E. Compilation fails because of an error in line 22.
F. Compilation fails because of an error in line 31.
Answer: E
QUESTION 55
Given:
6. public class Threads2 implements Runnable {
7.
8. public void run() {
9. System.out.println("run.");
10. throw new RuntimeException("Problem");
11. }
12. public static void main(String[] args) {
13. Thread t = new Thread(new Threads2());
14. t.start();
15. System.out.println("End of method.");
16. }
17. }
Which two can be results? (Choose two.)
: 가능한 두 개의 결과는 무엇인가? (2개를 고르시오.)
A. java.lang.RuntimeException: Problem
B. run. java.lang.RuntimeException: Problem
C. End of method. java.lang.RuntimeException: Problem
D. End of method. run. java.lang.RuntimeException: Problem
E. run. java.lang.RuntimeException: Problem End of method.
Answer: DE
QUESTION 56
Which two classes correctly implement both the java.lang.Runnable and the java.lang.
Cloneable interfaces? (Choose two.)
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 57
Given:
class Foo {
public int a = 3;
public void addFive() { a += 5; System.out.print("f "); }
}
class Bar extends Foo {
public int a = 8;
public void addFive() { this.a += 5; System.out.print("b " ); }
}
Invoked with:
Foo f = new Bar();
f.addFive();
System.out.println(f.a);
What is the result?
: 결과는 무엇인가?
A. b 3
B. b 8
C. b 13
D. f 3
E. f 8
F. f 13
G. Compilation fails.
H. An exception is thrown at runtime.
Answer: A
QUESTION 58
Given:
import java.util.TreeSet;
public class Explorer2 {
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++)
if(i%2 == 0) s.add(i);
subs = (TreeSet)s.subSet(608, true, 611, true);
s.add(629);
System.out.println(s + " " + subs);
}
}
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. An exception is thrown at runtime.
C. [608, 610, 612, 629] [608, 610]
D. [608, 610, 612, 629] [608, 610, 629]
E. [606, 608, 610, 612, 629] [608, 610]
F. [606, 608, 610, 612, 629] [608, 610, 629]
Answer: E
QUESTION 59
Given:
11. //insert code here
12. private N min, max;
13. public N getMin() { return min; }
14. public N getMax() { return max; }
15. public void add(N added) {
16. if (min == null || added.doubleValue() < min.doubleValue())
17. min = added;
18. if (max == null || added.doubleValue() > max.doubleValue())
19. max = added;
20. }
21. }
Which two, inserted at line 11, will allow the code to compile? (Choose two.)
:
A. public class MinMax<?> {
B. public class MinMax<? extends Number> {
C. public class MinMax<N extends Object> {
D. public class MinMax<N extends Number> {
E. public class MinMax<? extends Object> {
F. public class MinMax<N extends Integer> {
Answer: DF
이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
I'd like to leave my child here.
: 우리 아이를 맡기고 싶어요.
How old is he?
: 몇 살이에요?
댓글 없음:
댓글 쓰기