카테고리 없음
OCJP Study 16
Soul-Learner
2013. 12. 30. 17:39
OCJP(Java 6) 기출문제 연습 16(151~160)
PC나 스마트폰에서도 동일하게 실행되므로 장소를 가리지 않고 OCJP(JAVA 6) 국제 자격증을 목표로 학습할 수 있다.
QUESTION 151
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?
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?
B
설명없음
QUESTION 152
A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable.
Which implementation of MinMax will compile?
A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable.
Which implementation of MinMax will compile?
A
설명없음
QUESTION 153
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]?
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]?
A,B
설명없음
QUESTION 154
Given:
1.
2.
3.
4.
5. class A {
6. void foo() throws Exception { throw new Exception(); }
7. }
8. class SubB2 extends A {
9. 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?
Given:
1.
2.
3.
4.
5. class A {
6. void foo() throws Exception { throw new Exception(); }
7. }
8. class SubB2 extends A {
9. 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?
D
error "Unhandled exception type Exception" on line 14
ZZZ
ZZZ
QUESTION 155
Given:
try {
ResourceConnection con = resourceFactory.getConnection();
Results r = con.query("GET INFO FROM CUSTOMER"); // Linea 86
info = r.getData(); 88. con.close();
} catch (ResourceException re) {
errorLog.write(re.getMessage());
}
return info;
Which statement is true if a ResourceException is thrown on line 86?
Given:
try {
ResourceConnection con = resourceFactory.getConnection();
Results r = con.query("GET INFO FROM CUSTOMER"); // Linea 86
info = r.getData(); 88. con.close();
} catch (ResourceException re) {
errorLog.write(re.getMessage());
}
return info;
Which statement is true if a ResourceException is thrown on line 86?
C
설명없음
QUESTION 156
Given:
public class Breaker {
static String o = "";
public static void main(String[] args) {
z: o = o + 2;
for (int x = 3; x < 8; x++) {
if (x == 4)
break;
if (x == 6)
break z;
o = o + x;
}
System.out.println(o);
}
}
What is the result?
Given:
public class Breaker {
static String o = "";
public static void main(String[] args) {
z: o = o + 2;
for (int x = 3; x < 8; x++) {
if (x == 4)
break;
if (x == 6)
break z;
o = o + x;
}
System.out.println(o);
}
}
What is the result?
G
The label z: should be right before the for to compile. And if it executes the output would be 23
ZZZ
ZZZ
QUESTION 157
Given:
public void go(int x) {
assert (x > 0); //Line 12
switch(x) {
case 2: ;
default: assert false; //Line 15
}
}
private void go2(int x) { assert (x < 0); } //Line 18
Which statement is true?
Given:
public void go(int x) {
assert (x > 0); //Line 12
switch(x) {
case 2: ;
default: assert false; //Line 15
}
}
private void go2(int x) { assert (x < 0); } //Line 18
Which statement is true?
G
설명없음
QUESTION 158
Given:
public static void main(String[] args) {
try {
args = null;
args[0] = "test";
System.out.println(args[0]);
} catch (Exception ex) {
System.out.println("Exception");
} catch (NullPointerException npe) {
System.out.println("NullPointerException");
}
}
What is the result?
Given:
public static void main(String[] args) {
try {
args = null;
args[0] = "test";
System.out.println(args[0]);
} catch (Exception ex) {
System.out.println("Exception");
} catch (NullPointerException npe) {
System.out.println("NullPointerException");
}
}
What is the result?
C
It gives the compilation error "Unreachable catch block for NullPointerException. It is already handled by the
catch block for Exception" on line with the second catch.
ZZZ
ZZZ
QUESTION 159
Given:
public static void main(String[] args) {
for (int i = 0; i <= 10; i++) {
if (i > 6) break;
}
System.out.println(i);
}
What is the result?
Given:
public static void main(String[] args) {
for (int i = 0; i <= 10; i++) {
if (i > 6) break;
}
System.out.println(i);
}
What is the result?
E
error on println line: "i cannot be resolved to a variable"
ZZZ
ZZZ
QUESTION 160
Given:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
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?
Given:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
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 Exception in thread "main" java.lang.RuntimeException
at SubB.foo(SubB.java:5)
at SubB.main(SubB.java:9)
at SubB.foo(SubB.java:5)
at SubB.main(SubB.java:9)