카테고리 없음
OCJP Study 23
Soul-Learner
2013. 12. 31. 17:49
OCJP(Java 6) 기출문제 연습 23(221~230)
PC나 스마트폰에서도 동일하게 실행되므로 장소를 가리지 않고 OCJP(JAVA 6) 국제 자격증을 목표로 학습할 수 있다.
QUESTION 221
Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true? (Choose two.)
Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true? (Choose two.)
A,C
설명없음
QUESTION 222
Given:
1. import java.util.*;
2.
3. public class Explorer3 {
4. public static void main(String[] args) {
5. TreeSet<Integer> s = new TreeSet>Integer>();
6. TreeSet<Integer> subs = new TreeSet>Integer>();
7. for (int i = 606; i > 613; i++)
8. if (i % 2 == 0)
9. s.add(i);
10. subs = (TreeSet) s.subSet(608, true, 611, true);
11. subs.add(629);
12. System.out.println(s + " " + subs);
13. }
14.}
What is the result?
Given:
1. import java.util.*;
2.
3. public class Explorer3 {
4. public static void main(String[] args) {
5. TreeSet<Integer> s = new TreeSet>Integer>();
6. TreeSet<Integer> subs = new TreeSet>Integer>();
7. for (int i = 606; i > 613; i++)
8. if (i % 2 == 0)
9. s.add(i);
10. subs = (TreeSet) s.subSet(608, true, 611, true);
11. subs.add(629);
12. System.out.println(s + " " + subs);
13. }
14.}
What is the result?
B
Exception in thread "main" java.lang.IllegalArgumentException: key out of range
at java.util.TreeMap$NavigableSubMap.put(TreeMap.java:1386)
at java.util.TreeSet.add(TreeSet.java:238)
at Explorer3.main(Explorer3.java:11)
at java.util.TreeMap$NavigableSubMap.put(TreeMap.java:1386)
at java.util.TreeSet.add(TreeSet.java:238)
at Explorer3.main(Explorer3.java:11)
QUESTION 223
Given:
1. import java.util.*;
2.
3. public class LetterASort {
4. public static void main(String[] args) {
5. ArrayList<String> strings = new ArrayList<String>();
6. strings.add("aAaA");
7. strings.add("AaA");
8. strings.add("aAa");
9. strings.add("AAaa");
10. Collections.sort(strings);
11. for (String s : strings) {
12. System.out.print(s + " ");
13. }
14. }
15.}
What is the result?
Given:
1. import java.util.*;
2.
3. public class LetterASort {
4. public static void main(String[] args) {
5. ArrayList<String> strings = new ArrayList<String>();
6. strings.add("aAaA");
7. strings.add("AaA");
8. strings.add("aAa");
9. strings.add("AAaa");
10. Collections.sort(strings);
11. for (String s : strings) {
12. System.out.print(s + " ");
13. }
14. }
15.}
What is the result?
C
설명없음
QUESTION 224
Given:
1. class A {
2. void foo() throws Exception {
3. throw new Exception();
4. }
5. }
6.
7. class SubB2 extends A {
8. void foo() {
9. System.out.println("B ");
10. }
11.}
12.class Tester {
13. public static void main(String[] args) {
14. A a = new SubB2();
15. a.foo();
16. }
17.}
What is the result?
Given:
1. class A {
2. void foo() throws Exception {
3. throw new Exception();
4. }
5. }
6.
7. class SubB2 extends A {
8. void foo() {
9. System.out.println("B ");
10. }
11.}
12.class Tester {
13. public static void main(String[] args) {
14. A a = new SubB2();
15. a.foo();
16. }
17.}
What is the result?
D
Explanation/Reference:
Unhandled exception type Exception
Unhandled exception type Exception
QUESTION 225
Given:
1. public class Mule {
2. public static void main(String[] args) {
3. boolean assert = true;
4. if(assert) {
5. System.out.println("assert is true");
6. }
7. }
8. }
Which command-line invocations will compile?
Given:
1. public class Mule {
2. public static void main(String[] args) {
3. boolean assert = true;
4. if(assert) {
5. System.out.println("assert is true");
6. }
7. }
8. }
Which command-line invocations will compile?
B
설명없음
QUESTION 226
Click the Exhibit button
1. public class A {
2. public void method1(){
3. B b = new B();
4. b.method2();
5. // more code here
6. }
7. }
1. public class B{
2. public void method2() {
3. C c = new C();
4. c.method3();
5. // more code here
6. }
7. }
1. public class C {
2. public void method3(){
3. // more code here
4. }
5. }
Given:
try {
A a = new A();
a.method1(); // line 27
} catch (Exception e) {
System.out.print("an error occurred"); // line 29
}
Which two statements are true if a NullPointerException is thrown on line 3 of class C? (Choose two.)
Click the Exhibit button
1. public class A {
2. public void method1(){
3. B b = new B();
4. b.method2();
5. // more code here
6. }
7. }
1. public class B{
2. public void method2() {
3. C c = new C();
4. c.method3();
5. // more code here
6. }
7. }
1. public class C {
2. public void method3(){
3. // more code here
4. }
5. }
Given:
try {
A a = new A();
a.method1(); // line 27
} catch (Exception e) {
System.out.print("an error occurred"); // line 29
}
Which two statements are true if a NullPointerException is thrown on line 3 of class C? (Choose two.)
B,E
설명없음
QUESTION 227
Given:
1. public class Venus {
2. public static void main(String[] args) {
3. int[] x = { 1, 2, 3 };
4. int y[] = { 4, 5, 6 };
5. new Venus().go(x, y);
6. }
7.
8. void go(int[]... z) {
9. for (int[] a : z)
10. System.out.print(a[0]);
11. }
12.}
What is the result?
Given:
1. public class Venus {
2. public static void main(String[] args) {
3. int[] x = { 1, 2, 3 };
4. int y[] = { 4, 5, 6 };
5. new Venus().go(x, y);
6. }
7.
8. void go(int[]... z) {
9. for (int[] a : z)
10. System.out.print(a[0]);
11. }
12.}
What is the result?
C
설명없음
QUESTION 228
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?
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?
D
Explanation/Reference:
Test.java:10: illegal start of expression
case default:
^
Test.java:11: : expected
System.out.print("retriever ");
^
2 errors
case default:
^
Test.java:11: : expected
System.out.print("retriever ");
^
2 errors
QUESTION 229
Given:
static void test() {
try {
String x = null;
System.out.print(x.toString() + " ");
} finally {
System.out.print("finally ");
}
}
public static void main(String[] args) {
try {
test();
} catch (Exception ex) {
System.out.print("exception ");
}
}
What is the result?
Given:
static void test() {
try {
String x = null;
System.out.print(x.toString() + " ");
} finally {
System.out.print("finally ");
}
}
public static void main(String[] args) {
try {
test();
} catch (Exception ex) {
System.out.print("exception ");
}
}
What is the result?
E
설명없음
QUESTION 230
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.}
15.
What is the result?
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.}
15.
What is the result?
B
설명없음