카테고리 없음
OCJP Study 20
Soul-Learner
2013. 12. 31. 15:46
OCJP(Java 6) 기출문제 연습 20(191~200)
PC나 스마트폰에서도 동일하게 실행되므로 장소를 가리지 않고 OCJP(JAVA 6) 국제 자격증을 목표로 학습할 수 있다.
QUESTION 191
Given:
class Alpha {
public void foo() { System.out.print("Afoo "); }
}
public class Beta extends Alpha {
public void foo() { System.out.print("Bfoo "); }
public static void main(String[] args) {
Alpha a = new Beta();
Beta b = (Beta)a;
a.foo();
b.foo();
}
}
What is the result?
Given:
class Alpha {
public void foo() { System.out.print("Afoo "); }
}
public class Beta extends Alpha {
public void foo() { System.out.print("Bfoo "); }
public static void main(String[] args) {
Alpha a = new Beta();
Beta b = (Beta)a;
a.foo();
b.foo();
}
}
What is the result?
D
설명없음
QUESTION 191
Given:
1. public class TestOne {
2. public static void main (String[] args) throws Exception {
3. Thread.sleep(3000);
4. System.out.println("sleep");
5. }
6. }
What is the result?
Given:
1. public class TestOne {
2. public static void main (String[] args) throws Exception {
3. Thread.sleep(3000);
4. System.out.println("sleep");
5. }
6. }
What is the result?
C
설명없음
QUESTION 193
Given:
1. public class Threads3 implements Runnable {
2. public void run() {
3. System.out.print("running");
4. }
5. public static void main(String[] args) {
6. Thread t = new Thread(new Threads3());
7. t.run();
8. t.run();
9. t.start();
10. }
11.}
What is the result?
Given:
1. public class Threads3 implements Runnable {
2. public void run() {
3. System.out.print("running");
4. }
5. public static void main(String[] args) {
6. Thread t = new Thread(new Threads3());
7. t.run();
8. t.run();
9. t.start();
10. }
11.}
What is the result?
E
설명없음
QUESTION 194
Given:
public class NamedCounter {
private final String name;
private int count;
public NamedCounter(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void increment() {
count++;
}
public int getCount() {
return count;
}
public void reset() {
count = 0;
}
}
Which three changes should be made to adapt this class to be used safely by multiple threads? (Choose three.)
Given:
public class NamedCounter {
private final String name;
private int count;
public NamedCounter(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void increment() {
count++;
}
public int getCount() {
return count;
}
public void reset() {
count = 0;
}
}
Which three changes should be made to adapt this class to be used safely by multiple threads? (Choose three.)
A,C,E
설명없음
QUESTION 195
Given that Triangle implements Runnable, and:
void go() throws Exception {
Thread t = new Thread(new Triangle());
t.start();
for(int x = 1; x < 100000; x++) {
//insert code here Linea 35
if(x%100 == 0) System.out.print("g");
}
}
public void run() {
try {
for(int x = 1; x < 100000; x++) {
// insert the same code here Linea 41
if(x%100 == 0) System.out.print("t");
}
} catch (Exception e) {
}
}
Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute? (Choose two.)
Given that Triangle implements Runnable, and:
void go() throws Exception {
Thread t = new Thread(new Triangle());
t.start();
for(int x = 1; x < 100000; x++) {
//insert code here Linea 35
if(x%100 == 0) System.out.print("g");
}
}
public void run() {
try {
for(int x = 1; x < 100000; x++) {
// insert the same code here Linea 41
if(x%100 == 0) System.out.print("t");
}
} catch (Exception e) {
}
}
Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute? (Choose two.)
C,D
설명없음
QUESTION 196
Given:
1. public class TestSeven extends Thread {
2. private static int x;
3. public synchronized void doThings() {
4. int current = x;
5. current++;
6. x = current;
7. }
8. public void run() {
9. doThings();
10. }
11.}
Which statement is true?
Given:
1. public class TestSeven extends Thread {
2. private static int x;
3. public synchronized void doThings() {
4. int current = x;
5. current++;
6. x = current;
7. }
8. public void run() {
9. doThings();
10. }
11.}
Which statement is true?
E
설명없음
QUESTION 197
Given:
public class Yikes {
public static void go(Long n) {
System.out.print("Long ");
}
public static void go(Short n) {
System.out.print("Short ");
}
public static void go(int n) {
System.out.print("int ");
}
public static void main(String[] args) {
short y = 6;
long z = 7;
go(y);
go(z);
}
}
What is the result?
Given:
public class Yikes {
public static void go(Long n) {
System.out.print("Long ");
}
public static void go(Short n) {
System.out.print("Short ");
}
public static void go(int n) {
System.out.print("int ");
}
public static void main(String[] args) {
short y = 6;
long z = 7;
go(y);
go(z);
}
}
What is the result?
A
설명없음
QUESTION 198
Given:
12. Date date = new Date();
13. df.setLocale(Locale.ITALY);
14. String s = df.format(date);
The variable df is an object of type DateFormat that has been initialized in line 11.
What is the result if this code is run on December 14, 2000?
Given:
12. Date date = new Date();
13. df.setLocale(Locale.ITALY);
14. String s = df.format(date);
The variable df is an object of type DateFormat that has been initialized in line 11.
What is the result if this code is run on December 14, 2000?
D
The method setLocale(Locale) is undefined for the type DateFormat
QUESTION 199
Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)
Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)
A,B
설명없음
QUESTION 200
Given that c is a reference to a valid java.io.Console object, and:
11. String pw = c.readPassword("%s", "pw: ");
12. System.out.println("got " + pw);
13. String name = c.readLine("%s", "name: ");
14. System.out.println(" got ", name);
If the user types fido when prompted for a password, and then responds bob when prompted for a name,
what is the result?
Given that c is a reference to a valid java.io.Console object, and:
11. String pw = c.readPassword("%s", "pw: ");
12. System.out.println("got " + pw);
13. String name = c.readLine("%s", "name: ");
14. System.out.println(" got ", name);
If the user types fido when prompted for a password, and then responds bob when prompted for a name,
what is the result?
E
The method println(String) in the type PrintStream is not applicable for the arguments
(String, String)
(String, String)