Name : OCJP Study
Category : Software
Purpose : JAVA 공부하면서 OCJP 가 합격이 되도록 비나이다.
compatibility : ...
Etc : eclipse
공부한 거는 Post 하자.!!!
JAVA도 공부하면서 OCJP 도 한번에 합격하시기를...
지금 이글을 읽을 정도로 자신의 시간을 투자하는 사람이라면 합격은 당연한것인가. 흠.
그럼 시작.
QUESTION 41
Given:
public class Test {
public enum Dogs {collie, harrier};
public static void main(String [] args) {
Dogs myDog = Dogs.collie;
switch (myDog) {
case collie:
System.out.print("collie ");
case harrier:
System.out.print("harrier ");
}
}
}
What is the result?
: 결과는 무엇인가?
A. collie
B. harrier
C. Compilation fails.
D. collie harrier
E. An exception is thrown at runtime.
Answer: D
QUESTION 42
Given:
public class Donkey {
public static void main(String[] args) {
boolean assertsOn = false;
assert (assertsOn) : assertsOn = true;
if(assertsOn) {
System.out.println("assert is on");
}
}
}
If class Donkey is invoked twice, the first time without assertions enabled, and the second time with assertions enabled, what are the results?
: Donkey 클래스가 두번 호출된다면, 처음에는 assertions를 사용하지 않고, 두번째에는 assertions를 사용한다면, 결과는 무엇인가?
A. no output
B. no output assert is on
C. assert is on
D. no output An AssertionError is thrown.
E. assert is on An AssertionError is thrown.
Answer: D
QUESTION 43
Given:
01. static void test() throws Error {
02. if (true) throw new AssertionError();
03. System.out.print("test ");
04. }
05. public static void main(String[] args) {
06. try { test(); }
07. catch (Exception ex) { System.out.print("exception "); }
08. System.out.print("end ");
09. }
10. }
What is the result?
: 결과는 무엇인가?
A. end
B. Compilation fails.
C. exception end
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main.
Answer: E
QUESTION 44
Given:
1. class TestException extends Exception { }
2. class A {
3. public String sayHello(String name) throws TestException {
4. if(name == null) throw new TestException();
5. return "Hello " + name;
6. }
7. }
8. public class TestA {
9. public static void main(String[] args) {
10. new A().sayHello("Aiko");
11. }
12. }
Which statement is true?
: 어느 문장이 사실인가?
A. Compilation succeeds.
B. Class A does not compile.
C. The method declared on line 9 cannot be modified to throw TestException.
D. TestA compiles if line 10 is enclosed in a try/catch block that catches TestException.
Answer: D
QUESTION 45
Given:
static class A {
void process() throws Exception { throw new Exception(); }
}
static class B extends A {
void process() { System.out.println("B"); }
}
public static void main(String[] args) {
new B().process();
}
What is the result?
: 결과는 무엇인가?
A. B
B. The code runs with no output.
C. Compilation fails because of an error in line 12.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.
Answer: A
QUESTION 46
Given:
public class Foo {
static int[] a;
static { a[0]=2; }
public static void main( String[] args ) {}
}
Which exception or error will be thrown when a programmer attempts to run this code?
: 프로그래머가 이 코드를 실행하려고 할 때, 어떤 예외나 에러가 발생하는가?
A. java.lang.StackOverflowError
B. java.lang.IllegalStateException
C. java.lang.ExceptionInInitializerError
D. java.lang.ArrayIndexOutOfBoundsException
Answer: C
QUESTION 47
Given:
11. public static void main(String[] args) {
12. Integer i = new Integer(1) + new Integer(2);
13. switch(i) {
14. case 3: System.out.println("three"); break;
15. default: System.out.println("other"); break;
16. }
17. }
What is the result?
: 결과는 무엇인가?
A. three
B. other
C. An exception is thrown at runtime.
D. Compilation fails because of an error on line 12.
E. Compilation fails because of an error on line 13.
F. Compilation fails because of an error on line 15.
Answer: A
QUESTION 48
Given:
1. public class TestString3 {
2. public static void main(String[] args) {
3. // insert code here
4.
5. System.out.println(s);
6. }
7. }
Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.)
:
A. String s = "123456789";
s = (s-"123").replace(1,3,"24") - "89";
B. StringBuffer s = new StringBuffer("123456789");
s.delete(0,3).replace(1,3,"24").delete(4,6);
C. StringBuffer s = new StringBuffer("123456789");
s.substring(3,6).delete(1,3).insert(1, "24");
D. StringBuilder s = new StringBuilder("123456789");
s.substring(3,6).delete(1,2).insert(1, "24");
E. StringBuilder s = new StringBuilder("123456789");
s.delete(0,3).delete(1,3).delete(2,5).insert(1, "24");
Answer: BE
Explanation:
1. substring- Returns a new String.
s.substring(3,6).delete(1,3).
2. delete- java.lang.StringBuilder.delete
3. String <> StringBuilder
QUESTION 49
Given:
1. d is a valid, non-null Date object
2. df is a valid, non-null DateFormat object set to the current locale
What outputs the current locale's country name and the appropriate version of d's date?
: 현재 지역 국가 이름과 d(Date object)의 날짜의 해당 버전을 출력하는 것은 무엇인가?
A. Locale loc = Locale.getLocale();
System.out.println(loc.getDisplayCountry()
+ " " + df.format(d));
B. Locale loc = Locale.getDefault();
System.out.println(loc.getDisplayCountry()
+ " " + df.format(d));
C. Locale loc = Locale.getLocale();
System.out.println(loc.getDisplayCountry()
+ " " + df.setDateFormat(d));
D. Locale loc = Locale.getDefault();
System.out.println(loc.getDisplayCountry()
+ " " + df.setDateFormat(d));
Answer: B
QUESTION 50
Given:
18. import java.util.Date;
19. import java.text.DateFormat;
20.
21. DateFormat df;
22. Date date = new Date();
23. //insert code here
24. String s = df.format(date);
Which code fragment, inserted at line 23, allows the code to compile?
: 23라인에 삽입하여, 코드를 컴파일하기 위한 코드 조각은 어느 것인가?
A. df = new DateFormat();
B. df = Date.getFormat();
C. df = date.getFormat();
D. df = DateFormat.getFormat();
E. df = DateFormat.getInstance();
Answer: E
QUESTION 51
Given:
1. public class BuildStuff {
2. public static void main(String[] args) {
3. Boolean test = new Boolean(true);
4. Integer x = 343;
5. Integer y = new BuildStuff().go(test, x);
6. System.out.println(y);
7. }
8. int go(Boolean b, int i) {
9. if(b) return (i/7);
10. return (i/49);
11. }
12. }
What is the result?
: 결과는 무엇인가?
A. 7
B. 49
C. 343
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: B
QUESTION 52
Given:
import java.io.*;
public class Forest implements Serializable {
private Tree tree = new Tree();
public static void main(String [] args) {
Forest f = new Forest();
try {
FileOutputStream fs = new FileOutputStream("Forest.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(f); os.close();
} catch (Exception ex) { ex.printStackTrace(); }
}
}
class Tree { }
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. An exception is thrown at runtime.
C. An instance of Forest is serialized.
D. An instance of Forest and an instance of Tree are both serialized.
Answer: B
QUESTION 53
Given:
04. import java.io.*;
05.
06. public class Talk {
07. public static void main(String[] args) {
08. Console c = new Console();
09. String pw;
10. System.out.print("password: ");
11. pw = c.readLine();
12. System.out.println("got " + pw);
13. }
14.}
If the user types the password aiko when prompted, what is the result?
: 메시지가 사용자 유형의 암호 aiko 일 경우, 결과는 무엇인가?
A. password: got
B. password: got aiko
C. password: aiko got aiko
D. An exception is thrown at runtime.
E. Compilation fails due to an error on line 8.
Answer: E
QUESTION 54
Given:
1. public class LineUp {
2. public static void main(String[] args) {
3. double d = 12.345;
4. // insert code here
5. }
6. }
Which code fragment, inserted at line 4, produces the output | 12.345|?
: 4라인에 삽입하여, | 12.345| 출력이 나오도록 하는 코드 조각은 어느 것인가?
A. System.out.printf("|%7d| \n", d);
B. System.out.printf("|%7f| \n", d);
C. System.out.printf("|%3.7d| \n", d);
D. System.out.printf("|%3.7f| \n", d);
E. System.out.printf("|%7.3d| \n", d);
F. System.out.printf("|%7.3f| \n", d);
Answer: F
QUESTION 55
Given:
1. public class Threads4 {
2. public static void main (String[] args) {
3. new Threads4().go();
4. }
5. public void go() {
6. Runnable r = new Runnable() {
7. public void run() {
8. System.out.print("foo");
9. }
10. };
11. Thread t = new Thread(r);
12. t.start();
13. t.start();
14. }
15. }
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes normally and prints foo.
D. The code executes normally, but nothing is printed.
Answer: B
QUESTION 56
Given:
1. public class Mud {
2. //insert code here
3. System.out.println("hi");
4. }
5. }
And the following five fragments:
public static void main(String...a) {
public static void main(String.* a) {
public static void main(String... a) {
public static void main(String[]... a) {
public static void main(String...[] a) {
How many of the code fragments, inserted independently at line 2, compile?
: 2라인에 독립적으로 삽입하여, 컴파일 되는 코드 조각은 몇 개인가?
A. 0
B. 1
C. 2
D. 3
E. 4
F. 5
Answer: D
QUESTION 57
Given:
static void test() throws RuntimeException {
try {
System.out.print("test ");
throw new RuntimeException();
}
catch (Exception ex) { System.out.print("exception "); }
}
public static void main(String[] args) {
try { test(); }
catch (RuntimeException ex) { System.out.print("runtime "); }
System.out.print("end ");
}
What is the result?
: 결과는 무엇인가?
A. test end
B. Compilation fails.
C. test runtime end
D. test exception end
E. A Throwable is thrown by main at runtime.
Answer: D
QUESTION 58
Given:
11. public class Test {
12. public static void main(String [] args) {
13. int x = 5;
14. boolean b1 = true;
15. boolean b2 = false;
16.
17. if ((x == 4) && !b2 )
18. System.out.print("1 ");
19. System.out.print("2 ");
20. if ((b2 = true) && b1 )
21. System.out.print("3 ");
22. }
23. }
What is the result?
: 결과는 무엇인가?
A. 2
B. 3
C. 1 2
D. 2 3
E. 1 2 3
F. Compilation fails.
G. An exception is thrown at runtime.
Answer: D
QUESTION 59
Given:
int x = 0;
int y = 10;
do {
y--;
++x;
} while (x < 5);
System.out.print(x + "," + y);
What is the result?
: 결과는 무엇인가?
A. 5,6
B. 5,5
C. 6,5
D. 6,6
Answer: B
QUESTION 60
Given:
3. import java.util.*;
4. public class Hancock {
5. // insert code here
6. list.add("foo");
7. }
8. }
Which two code fragments, inserted independently at line 5, will compile without warnings? (Choose two.)
: 5라인에 독립적으로 삽입하여, 경고 없이 컴파일되는 두 개의 코드 조각은 어느 것인가?
A. public void addStrings(List list) {
B. public void addStrings(List<String> list) {
C. public void addStrings(List<? super String> list) {
D. public void addStrings(List<? extends String> list) {
Answer: BC
이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
contend
v.동사 (특히 언쟁 중에) 주장하다
temper
n.명사 성질
deceive
v.동사 속이다, 기만하다
gabble
v.동사 빠르게 말하다, 지껄이다
all the same
똑같은, 아무래도 좋은
댓글 없음:
댓글 쓰기