카테고리 없음
OCJP Study 01
Soul-Learner
2013. 12. 26. 11:45
OCJP(Java 6) 기출문제 연습 1(1~10)
PC나 스마트폰에서도 동일하게 실행되므로 장소를 가리지 않고 OCJP(JAVA 6) 국제 자격증을 목표로 학습할 수 있다.
QUESTION 1
Given:
2.
public class Threads2 implements Runnable {
3.
4. public void run() {
5. System.out.println("run.");
6. throw new RuntimeException("Problem");
7. }
8. public static void main(String[] args) {
9. Thread t = new Thread(new Threads2());
10. t.start();
11. System.out.println("End of method.");
12. }
13.}
Which two can be results? (Choose two.)
Given:
2.
public class Threads2 implements Runnable {
3.
4. public void run() {
5. System.out.println("run.");
6. throw new RuntimeException("Problem");
7. }
8. public static void main(String[] args) {
9. Thread t = new Thread(new Threads2());
10. t.start();
11. System.out.println("End of method.");
12. }
13.}
Which two can be results? (Choose two.)
D,E
End of method.
run.
Exception in thread "Thread-0" java.lang.RuntimeException: Problem
at Threads2.run(Threads2.java:5)
at java.lang.Thread.run(Unknown Source)
run.
Exception in thread "Thread-0" java.lang.RuntimeException: Problem
at Threads2.run(Threads2.java:5)
at java.lang.Thread.run(Unknown Source)
QUESTION 2
Which two statements are true? (Choose two.)
Which two statements are true? (Choose two.)
A,F
설명없음
QUESTION 3
Given:
void waitForSignal() {
Object obj = new Object();
synchronized (Thread.currentThread()) {
obj.wait();
obj.notify();
}
}
Which statement is true?
Given:
void waitForSignal() {
Object obj = new Object();
synchronized (Thread.currentThread()) {
obj.wait();
obj.notify();
}
}
Which statement is true?
A
Threads2.java:15: unreported exception java.lang.InterruptedException; must
be caught or declared to be thrown
obj.wait();
^
1 error
obj.wait();
^
1 error
QUESTION 4
Click the Exhibit button.
What is the output if the main() method is run?
1. public class Starter extends Thread {
2. private int x = 2;
3. public static void main(String[] args) throws Exception {
4. new Starter().makeItSo();
5. }
6. public Starter(){
7. x = 5;
8. start();
9. }
10. public void makeItSo() throws Exception {
11. join();
12. x = x -1;
13. System.out.println(x);
14. }
15. public void run() { x *= 2; }
16.}
Click the Exhibit button.
What is the output if the main() method is run?
1. public class Starter extends Thread {
2. private int x = 2;
3. public static void main(String[] args) throws Exception {
4. new Starter().makeItSo();
5. }
6. public Starter(){
7. x = 5;
8. start();
9. }
10. public void makeItSo() throws Exception {
11. join();
12. x = x -1;
13. System.out.println(x);
14. }
15. public void run() { x *= 2; }
16.}
G
설명없음
QUESTION 5
Given:
1. class PingPong2 {
2. synchronized void hit(long n) {
3. for(int i = 1; i < 3; i++)
4. System.out.print(n + "-" + i + " ");
5. }
6. }
1. public class Tester implements Runnable {
2. static PingPong2 pp2 = new PingPong2();
3. public static void main(String[] args) {
4. new Thread(new Tester()).start();
5. new Thread(new Tester()).start();
6. }
7. public void run() { pp2.hit(Thread.currentThread().getId()); }
8. }
Which statement is true?
Given:
1. class PingPong2 {
2. synchronized void hit(long n) {
3. for(int i = 1; i < 3; i++)
4. System.out.print(n + "-" + i + " ");
5. }
6. }
1. public class Tester implements Runnable {
2. static PingPong2 pp2 = new PingPong2();
3. public static void main(String[] args) {
4. new Thread(new Tester()).start();
5. new Thread(new Tester()).start();
6. }
7. public void run() { pp2.hit(Thread.currentThread().getId()); }
8. }
Which statement is true?
B
설명없음
QUESTION 6
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?
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?
B
fooException in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Unknown Source)
at p6.Threads4.go(Threads4.java:15)
at p6.Threads4.main(Threads4.java:5)
at java.lang.Thread.start(Unknown Source)
at p6.Threads4.go(Threads4.java:15)
at p6.Threads4.main(Threads4.java:5)
QUESTION 7
Given:
1. public abstract class Shape {
2.
private int x;
3.
private int y;
4.
public abstract void draw();
5.
public void setAnchor(int x, int y) {
6. this.x = x;
7. this.y = y;
8.
}
9. }
Which two classes use the Shape class correctly? (Choose two.)
Given:
1. public abstract class Shape {
2.
private int x;
3.
private int y;
4.
public abstract void draw();
5.
public void setAnchor(int x, int y) {
6. this.x = x;
7. this.y = y;
8.
}
9. }
Which two classes use the Shape class correctly? (Choose two.)
B,E
설명없음
QUESTION 8
Given:
1. public class Barn {
2. public static void main(String[] args) {
3. new Barn().go("hi", 1);
4. new Barn().go("hi", "world", 2);
5. }
6. public void go(String... y, int x) {
7. System.out.print(y[y.length -1] + " ");
8. }
9. }
What is the result?
Given:
1. public class Barn {
2. public static void main(String[] args) {
3. new Barn().go("hi", 1);
4. new Barn().go("hi", "world", 2);
5. }
6. public void go(String... y, int x) {
7. System.out.print(y[y.length -1] + " ");
8. }
9. }
What is the result?
D
The method go(String[], int) in the type Barn is not applicable for the arguments (String, int)
The variable argument type String of the method go must be the last parameter
The variable argument type String of the method go must be the last parameter
QUESTION 9
Given:
1. class Nav{
2. public enum Direction { NORTH, SOUTH, EAST, WEST }
3. }
1. public class Sprite{
2. // insert code here
3. }
Which code, inserted at line 14, allows the Sprite class to compile?
Given:
1. class Nav{
2. public enum Direction { NORTH, SOUTH, EAST, WEST }
3. }
1. public class Sprite{
2. // insert code here
3. }
Which code, inserted at line 14, allows the Sprite class to compile?
D
설명없음
QUESTION 10
Click the Exhibit button.
Which statement is true about the classes and interfaces in the exhibit?
1. public interface A{
2. public void doSomething(String thing);
3. }
1. public class AImpl implements A{
2. public void doSomething(String msg) {}
3. }
1. public class B{
2. public A doit(){
3. //more code here
4. }
5. public String execute(){
6. //more code here
7. }
8. }
1. public class C extends B{
2. public AImpl doit(){
3. //more code here
4. }
5.
6. public Object execute() {
7. //more code here
8. }
9. }
Click the Exhibit button.
Which statement is true about the classes and interfaces in the exhibit?
1. public interface A{
2. public void doSomething(String thing);
3. }
1. public class AImpl implements A{
2. public void doSomething(String msg) {}
3. }
1. public class B{
2. public A doit(){
3. //more code here
4. }
5. public String execute(){
6. //more code here
7. }
8. }
1. public class C extends B{
2. public AImpl doit(){
3. //more code here
4. }
5.
6. public Object execute() {
7. //more code here
8. }
9. }
C
The return type is incompatible with B.execute()