2016년 8월 13일 토요일

OCJP - 1Z0-851(A-1) 공부하자!

Name : OCJP Study
Category : Software
Purpose : JAVA 공부하면서 OCJP 가 합격이 되도록 비나이다.
compatibility : ...
Etc : eclipse

공부한 거는 Post 하자.!!!

JAVA도 공부하면서 OCJP 도 한번에 합격하시기를...
지금 이글을 읽을 정도로 자신의 시간을 투자하는 사람이라면 합격은 당연한것인가. 흠.

그럼 시작.
QUESTION 1
Which two statements are true? (Choose two.)
: 어느 두 문장이 사실인가? (2개를 고르시오.)

A. It is possible for more than two threads to deadlock at once.
: 두 개 이상의 스레드가 한번에 교착하는 것이 가능하다.
B. The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state.
: JVM의 구현은 여러 스레드가 교착 상태에 들어갈 수 없음을 보장합니다.
C. Deadlocked threads release once their sleep() method's sleep duration has expired.
: sleep() 메소드의 sleep 시간이 만료되면 교착 상태 스레드를 풀어줍니다.
D. Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are used incorrectly.
: 교착 상태는 wait(), notify(), otifyAll () 메소드를 잘못 사용하는 경우에만 발생할 수 있습니다.
E. It is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly.
: 동기 블록을 잘못 사용되는 경우 단일 스레드 애플리케이션이 교착하는 것이 가능하다.
F. If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield().
: 코드 부분은 교착 할 경우 Thread.yield() 호출을 삽입함으로써 교착 가능성을 제거 할 수 없다.

Answer: AF


QUESTION 2 Given:
void waitForSignal() {
     Object obj = new Object();
     synchronized (Thread.currentThread()) {
obj.wait();
obj.notify();
     }
}
Which statement is true?
: 어떤 것이 사실인가?

A. This code can throw an InterruptedException.
B. This code can throw an IllegalMonitorStateException.
C. This code can throw a TimeoutException after ten minutes.
D. Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally.
E. A call to notify() or notifyAll() from another thread might cause this method to complete normally.
F. This code does NOT compile unless obj.wait() is replaced with ((Thread) obj).wait().

Answer: A


QUESTION 3
What is the output if the main() method is run?
: main() 메소드가 실행되는 경우 무엇이 출력됩니까?

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. }

A. 4
B. 5
C. 8
D. 9
E. Compilation fails.
F. An exception is thrown at runtime.
G. It is impossible to determine for certain.

Answer: D
: join() 공부
Waits for this thread to die.
: 이러한 맥락에서 죽을 때까지 기다립니다.
An invocation of this method behaves in exactly the same way as the invocation
: 이 메서드의 호출이 호출과 정확히 동일한 방식으로 행동한다.



QUESTION 4 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?
: 옳은 설명은?
A. The output could be 5-1 6-1 6-2 5-2
B. The output could be 6-1 6-2 5-1 5-2
C. The output could be 6-1 5-2 6-2 5-1
D. The output could be 6-1 6-2 5-1 7-1

Answer: B
: synchronized 공부




QUESTION 5 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.)
: Shape 클래스를 정확하게 사용한 두 개의 클래스는 어떤 것인가? (2개를 고르시오.)

A. public class Circle implements Shape {     private int radius; }
B. public abstract class Circle extends Shape {     private int radius; }
C. public class Circle extends Shape {     private int radius;     public void draw(); }
D. public abstract class Circle implements Shape {      private int radius;     public void draw(); }
E. public class Circle extends Shape {     private int radius;     public void draw() {/* code here */} } F. public abstract class Circle implements Shape {     private int radius;     public void draw() {/* code here */} }

Answer: BE


QUESTION 6 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?
: 결과는 무엇인가?

A. hi hi
B. hi world
C. world world
D. Compilation fails.
E. An exception is thrown at runtime.

Answer: D
:  variable argument 공부



QUESTION 7 Given:
09. class Nav{
10.    public enum Direction { NORTH, SOUTH, EAST, WEST }
11. }
12.
13. public class Sprite{
14.     //    insert code here
15. }
Which code, inserted at line 14, allows the Sprite class to compile?
: 14라인에 삽입되면, Sprite 클래스가 컴파일 될 수 있는 코드는 어느 것인가?

A. Direction d = NORTH;
B. Nav.Direction d = NORTH;
C. Direction d = Direction.NORTH;
D. Nav.Direction d = Nav.Direction.NORTH;

Answer: D


QUESTION 8
Which statement is true about the classes and interfaces?
: classes 와 interfaces 에 관련해서 사실인 것은?
 
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. }
A. Compilation will succeed for all classes and interfaces.
B. Compilation of class C will fail because of an error in line 2.
C. Compilation of class C will fail because of an error in line 6.
D. Compilation of class AImpl will fail because of an error in line 2.

Answer: C


QUESTION 9
What is the result?
: 결과는 무엇인가?

11. public class Person {
12.    String name = "No name";
13.    public Person(String nm) { name = nm; }
14. }
15.
16. public class Employee extends Person {
17.    String empID = "0000";
18.    public Employee(String id) { empID = id; }
19. }
20.
21. public class EmployeeTest {
22.    public static void main(String[] args){
23.        Employee e = new Employee("4321");
24.        System.out.println(e.empID);
25.    }
26. }
A. 4321
B. 0000
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 18.

Answer: D
: 상속 생성자 공부


QUESTION 10 Given:
1. public class Rainbow {
2.     public enum MyColor {
3.         RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);
4.         private final int rgb;
5.         MyColor(int rgb) { this.rgb = rgb; }
6.         public int getRGB() { return rgb; }
7.     };
8.     public static void main(String[] args) {
9.         //insert code here
10.     }
11. }
Which code fragment, inserted at line 19, allows the Rainbow class to compile?
: 19라인에 삽입되면, Rainbow 클래스가 컴파일 될 수 있는 코드 조각은 어느 것인가?

A. MyColor skyColor = BLUE;
B. MyColor treeColor = MyColor.GREEN;
C. if(RED.getRGB() < BLUE.getRGB()) { }
D. Compilation fails due to other error(s) in the code.
E. MyColor purple = new MyColor(0xff00ff);
F. MyColor purple = MyColor.BLUE + MyColor.RED;

Answer: B


QUESTION 11 Given:
1. class Atom {
2.     Atom() { System.out.print("atom "); }
3. }
4. class Rock extends Atom {
5.     Rock(String type) { System.out.print(type); }
6. }
7. public class Mountain extends Rock {
8.     Mountain() {
9.         super("granite ");
10.         new Rock("granite ");
11.     }
12.     public static void main(String[] a) { new Mountain(); }
13. }

What is the result?
: 결과는 무엇인가?

A. Compilation fails.
B. atom granite
C. granite granite
D. atom granite granite
E. An exception is thrown at runtime.
F. atom granite atom granite

Answer: F



QUESTION 12
Given:
01. interface TestA { String toString(); }
02.
03. public class Test {
04.     public static void main(String[] args) {
05.         System.out.println(new TestA() {
06.             public String toString() { return "test"; }
07.         });
08.     }
09. }
What is the result?
: 결과는 무엇인가?

A. test
B. null
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 1.
E. Compilation fails because of an error in line 4.
F. Compilation fails because of an error in line 5.

Answer: A


QUESTION 13
Given:
1.     public static void parse(String str) {
2.         try {
3.             float f = Float.parseFloat(str);
4.         } catch (NumberFormatException nfe) {
5.             f = 0;
6.         } finally {
7.             System.out.println(f);
8.         }
9.     }
10.     public static void main(String[] args) {
11.         parse("invalid");
12.     }
What is the result?
: 결과는 무엇인가?

A. 0.0
B. Compilation fails.
C. A ParseException is thrown by the parse method at runtime.
D. A NumberFormatException is thrown by the parse method at runtime.

Answer: B


QUESTION 14
Given:
1. public class Blip {
2.     protected int blipvert(int x) { return 0; }
3. }
4. class Vert extends Blip {
5.     //    insert code here
6. }
Which five methods, inserted independently at line 5, will compile? (Choose five.)
: 5줄에 독립적으로 삽입 되어 컴파일이 되는 다섯 메소트는 어느 것인가? (5개 고르시오.)

A. public int blipvert(int x) { return 0; }
B. private int blipvert(int x) { return 0; }
C. private int blipvert(long x) { return 0; }
D. protected long blipvert(int x) { return 0; }
E. protected int blipvert(long x) { return 0; }
F. protected long blipvert(long x) { return 0; }
G. protected long blipvert(int x, int y) { return 0; }

Answer: ACEFG


QUESTION 15
Given:
1. class Super {
2.    private int a;
3.    protected Super(int a) { this.a = a; }
4. }
11. class Sub extends Super {
12.    public Sub(int a) { super(a); }
13.    public Sub() { this.a = 5; }
14. }
Which two, independently, will allow Sub to compile? (Choose two.)
: 독립적으로 Sub 클래스가 컴파일 되도록 하는 2개는 어느 것인가? (2개를 고르시오.)

A. Change line 2 to: public int a;
B. Change line 2 to: protected int a;
C. Change line 13 to: public Sub() { this(5); }
D. Change line 13 to: public Sub() { super(5); }
E. Change line 13 to: public Sub() { super(a); }

Answer: CD


QUESTION 16
Which Man class properly represents the relationship "Man has a best friend who is a Dog"?
: Man 클래스가 "Man has a best friend who is a Dog" 관계로 제대로 표현된 것은 어느 것인가?

A. class Man extends Dog { }
B. class Man implements Dog { }
C. class Man { private BestFriend dog; }
D. class Man { private Dog bestFriend; }
E. class Man { private Dog<bestFriend>; }
F. class Man { private BestFriend<dog>; }

Answer: D


QUESTION 17
Given:
1. package test;
2.
3. class Target {
4.     public String name = "hello";
5. }
What can directly access and change the value of the variable name?
: 바로 접근할 수 있고, variable name 의 값을 변경할 수있는 것은 무엇인가?

A. any class
B. only the Target class
C. any class in the test package
D. any class that extends Target

Answer: C


QUESTION 18
Given:
11. abstract class Vehicle { public int speed() { return 0; }
12. class Car extends Vehicle { public int speed() { return 60; }
13. class RaceCar extends Car { public int speed() { return 150; } ...
21.    RaceCar racer = new RaceCar();
22.    Car car = new RaceCar();
23     Vehicle vehicle = new RaceCar();
24     System.out.println(racer.speed() + ", " + car.speed() + ", " + vehicle.speed());
What is the result?
: 결과는 무엇인가?

A. 0, 0, 0
B. 150, 60, 0
C. Compilation fails.
D. 150, 150, 150
E. An exception is thrown at runtime.

Answer: D


QUESTION 19
Given:
5. class Building { }
6. public class Barn extends Building {
7.    public static void main(String[] args) {
8.        Building build1 = new Building();
9.        Barn barn1 = new Barn();
10.       Barn barn2 = (Barn) build1;
11.       Object obj1 = (Object) build1;
12.       String str1 = (String) build1;
13.       Building build2 = (Building) barn1;
14.   }
15. }
Which is true?
: 사실인 것은?

A. If line 10 is removed, the compilation succeeds.
B. If line 11 is removed, the compilation succeeds.
C. If line 12 is removed, the compilation succeeds.
D. If line 13 is removed, the compilation succeeds.
E. More than one line must be removed for compilation to succeed.

Answer: C


QUESTION 20
A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing any functionality. If they implement the new design, which two OO principles will they be promoting?


A. Looser coupling
: 느슨한 결합
B. Tighter coupling
: 강한 결합
C. Lower cohesion
: 낮은 응집력
D. Higher cohesion
: 강한 응집력
E. Weaker encapsulation
: 약한 캡슐화
F. Stronger encapsulation
: 강한 캡슐화

Answer: AD

이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
Is the fish fresh? 
: 이 생선 싱싱해요?
Yes. It was delivered today. 
: 네, 오늘 들어왔어요.

댓글 없음:

댓글 쓰기

대항해시대 조선 랭작

숙련도 획득 방법 선박 건조, 선박 강화, 전용함 추가시 숙련도 획득 모두 동일한 공식 적용 획득 숙련도 공식 기본 획득 숙련도 ≒ int{건조일수 × 현재랭크 × (0.525)} 이벤트 & 아이템 사용...