카테고리 없음
OCJP Study 12
Soul-Learner
2013. 12. 29. 12:58
OCJP(Java 6) 기출문제 연습 12(111~120)
PC나 스마트폰에서도 동일하게 실행되므로 장소를 가리지 않고 OCJP(JAVA 6) 국제 자격증을 목표로 학습할 수 있다.
QUESTION 111
Given:
public static Collection get() {
Collection sorted = new LinkedList();
sorted.add("B"); sorted.add("C"); sorted.add("A");
return sorted;
}
public static void main(String[] args) {
for (Object obj: get()) {
System.out.print(obj + ", ");
}
}
What is the result?
Given:
public static Collection get() {
Collection sorted = new LinkedList();
sorted.add("B"); sorted.add("C"); sorted.add("A");
return sorted;
}
public static void main(String[] args) {
for (Object obj: get()) {
System.out.print(obj + ", ");
}
}
What is the result?
B
설명없음
QUESTION 112
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?
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
설명없음
QUESTION 113
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?
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?
C
설명없음
QUESTION 114
Given:
public static void main(String[] args) {
Integer i = new Integer(1) + new Integer(2);
switch(i) {
case 3: System.out.println("three"); break;
default: System.out.println("other"); break;
}
}
What is the result?
Given:
public static void main(String[] args) {
Integer i = new Integer(1) + new Integer(2);
switch(i) {
case 3: System.out.println("three"); break;
default: System.out.println("other"); break;
}
}
What is the result?
A
설명없음
QUESTION 115
Given:
public static Iterator reverse(List list) {
Collections.reverse(list);
return list.iterator();
}
public static void main(String[] args) {
List list = new ArrayList();
list.add("1"); list.add("2"); list.add("3");
for (Object obj: reverse(list))
System.out.print(obj + ", ");
}
What is the result?
Given:
public static Iterator reverse(List list) {
Collections.reverse(list);
return list.iterator();
}
public static void main(String[] args) {
List list = new ArrayList();
list.add("1"); list.add("2"); list.add("3");
for (Object obj: reverse(list))
System.out.print(obj + ", ");
}
What is the result?
C
In the line of the for it gives the compilation error "Can only iterate over an array or an instance of java.lang.
Iterable" for the text "reverse(list)"
ZZZ
Iterable" for the text "reverse(list)"
ZZZ
QUESTION 116
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.)
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.)
B,C
설명없음
QUESTION 117
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?
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?
B
설명없음
QUESTION 118
Given:
import java.util.Date;
import java.text.DateFormat;
DateFormat df;
Date date = new Date();
//insert code here Linea 23
String s = df.format(date);
Which code fragment, inserted at line 23, allows the code to compile?
Given:
import java.util.Date;
import java.text.DateFormat;
DateFormat df;
Date date = new Date();
//insert code here Linea 23
String s = df.format(date);
Which code fragment, inserted at line 23, allows the code to compile?
E
설명없음
QUESTION 119
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?
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?
B
Tested and confirmed.
ZZZ
ZZZ
QUESTION 120
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?
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?
B
Tested and it throws the following exception at run-time: "java.io.NotSerializableException: Tree" on the
command "os.writeObject(f);"
ZZZ
ZZZ