2016년 8월 13일 토요일

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

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

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

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

그럼 시작.
QUESTION 21 Given:
21. class Money {
22.    private String country = "Canada";
23.    public String getC() { return country; }
24. }
25. class Yen extends Money {
26.    public String getC() { return super.country; }
27. }
28. public class Euro extends Money {
29.    public String getC(int x) { return super.getC(); }
30.    public static void main(String[] args) {
31.        System.out.print(new Yen().getC() + " " + new Euro().getC());
32.    }
33. }
What is the result?
: 결과는 무엇인가?

A. Canada
B. null Canada
C. Canada null
D. Canada Canada
E. Compilation fails due to an error on line 26.
F. Compilation fails due to an error on line 29.
 
Answer: E


QUESTION 22
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:
: serializeBanana() 와 deserializeBanana() 메소드가 제대로 자바 직렬화를 사용한다고 가정.

13. import java.io.*;
14. class Food implements Serializable {int good = 3;}
15. class Fruit extends Food {int juice = 5;}
16. public class Banana extends Fruit {
17.    int yellow = 4;
18.    public static void main(String [] args) {
19.        Banana b = new Banana(); Banana b2 = new Banana();
20.        b.serializeBanana(b); // assume correct serialization
21.        b2 = b.deserializeBanana(); // assume correct
22.        System.out.println("restore "+b2.yellow+ b2.juice+b2.good);
24.    }
25. //    more Banana methods go here
50. }
What is the result?
: 결과는 무엇인가?

A. restore 400
B. restore 403
C. restore 453
D. Compilation fails.
E. An exception is thrown at runtime.

Answer: C


QUESTION 23
Given a valid DateFormat object named df, and
: df라는 이름이 유효한 날짜 형식 개체가 주어지고,

16. Date d = new Date(0L);
17. String ds = "December 15, 2004";
18. //insert code here

What updates d's value with the date represented by ds?
: ds가 나타내는 날짜와 d의 값을 업데이트하는 것은 무엇인가?

A. 18. d = df.parse(ds);
B. 18. d = df.getDate(ds);
C. 18. try {
   19. d = df.parse(ds);
   20. } catch(ParseException e) { };
D. 18. try {
   19. d = df.getDate(ds);
   20. } catch(ParseException e) { };
 
Answer: C


QUESTION 24
Given:
11. double input = 314159.26;
12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN);
13. String b;
14. //insert code here

Which code, inserted at line 14, sets the value of b to 314.159,26?
: 14라인에 삽입하여 b의 값이 314.159,26으로 설정되는 것은 어느 코드인가?

A. b = nf.parse( input );
B. b = nf.format( input );
C. b = nf.equals( input );
D. b = nf.parseObject( input );
 
Answer: B


QUESTION 25
Given:
1. public class TestString1 {
2.     public static void main(String[] args) {
3.         String str = "420";
4.         str += 42;
5.         System.out.print(str);
6.     }
7. }

What is the output?
: 무엇이 출력되는가?

A. 42
B. 420
C. 462
D. 42042
E. Compilation fails.
F. An exception is thrown at runtime.

Answer: D


QUESTION 26
Which capability exists only in java.io.FileWriter?
: java.io.FileWriter 에만 존재하는 기능은 어느 것인가?

A. Closing an open stream.
B. Flushing an open stream.
C. Writing to an open stream.
D. Writing a line separator to an open stream.
: 열린 스트림에 행 분리를 작성

Answer: D


QUESTION 27
Given that the current directory is empty, and that the user has read and write permissions, and the following:

1. import java.io.*;
2. public class DOS {
3.     public static void main(String[] args) {
4.         File dir = new File("dir");
5.         dir.mkdir();
6.         File f1 = new File(dir, "f1.txt");
7.         try {
8.             f1.createNewFile();
9.         } catch (IOException e) { ; }
10.         File newDir = new File("newDir");
11.         dir.renameTo(newDir);
12.     }
13. }

Which statement is true?
: 어떤 문장이 사실인가?

A. Compilation fails.
B. The file system has a new empty directory named dir.
C. The file system has a new empty directory named newDir.
D. The file system has a directory named dir, containing a file f1.txt.
E. The file system has a directory named newDir, containing a file f1.txt.

Answer: E


QUESTION 28 Given:
1. public class Score implements Comparable<Score> {
2.     private int wins, losses;
3.     public Score(int w, int l) { wins = w; losses = l; }
4.     public int getWins() { return wins; }
5.     public int getLosses() { return losses; }
6.     public String toString() {
7.         return "<" + wins + "," + losses + ">";
8.     }
9. //    insert code here
10. }

Which method will complete this class?
: 어느 메소드가 클래스를 완료할 것인가?

A. public int compareTo(Object o){/*more code here*/}
B. public int compareTo(Score other){/*more code here*/}
C. public int compare(Score s1,Score s2){/*more code here*/}
D. public int compare(Object o1,Object o2){/*more code here*/}  

Answer: B


QUESTION 29
Given:
22. StringBuilder sb1 = new StringBuilder("123");
23. String s1 = "123";
24. // insert code here
25. System.out.println(sb1 + " " + s1);

Which code fragment, inserted at line 24, outputs 123abc 123abc?
: 24라인에 삽입하여 123abc 123abc 출력물이 나오는 코드 조각은 어느 것인가?

A. sb1.append("abc"); s1.append("abc");
B. sb1.append("abc"); s1.concat("abc");
C. sb1.concat("abc"); s1.append("abc");
D. sb1.concat("abc"); s1.concat("abc");
E. sb1.append("abc"); s1 = s1.concat("abc");
F. sb1.concat("abc"); s1 = s1.concat("abc");
G. sb1.append("abc"); s1 = s1 + s1.concat("abc");
H. sb1.concat("abc"); s1 = s1 + s1.concat("abc");

Answer: E


QUESTION 30
Click the Exhibit button.
Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?
: 14라인에 삽입하여 이 클래스가 serialize 와 deserialize를 올바르게 허용하는 코드는 어느 것인가?

1. import java.io.*;
2. public class Foo implements Serializable {
3.     public int x, y;
4.     public Foo(int x, int y){
5.         this.x = x; this.y = y;
6.     }
7.    
8.     private void writeObject(ObjectOutputStream s)
9.         throws IOException{
10.         s.writeInt(x); s.writeInt(y);
11.     }
12.    
13.     private void readObject(ObjectInputStream s)
14.         throws IOException, ClassNotFoundException {
15.         //insert code here
16.     }
17.  }  

A. s.defaultReadObject();
B. this = s.defaultReadObject();
C. y = s.readInt(); x = s.readInt();
D. x = s.readInt(); y = s.readInt();

Answer: D


QUESTION 31
Given:
interface Foo {}
class Alpha implements Foo {}
class Beta extends Alpha {}
class Delta extends Beta {    
public static void main( String[] args ) {        
Beta x = new Beta();
16.  //insert code here    
}
}

Which code, inserted at line 16, will cause a java.lang.ClassCastException?


A. Alpha a = x;
B. Foo f = (Delta)x;
C. Foo f = (Alpha)x;
D. Beta b = (Beta)(Alpha)x;

Answer: B


QUESTION 32
Given:
public void go() {    
String o = "";    
z:        
for(int x = 0; x < 3; x++) {            
for(int y = 0; y < 2; y++) {                
if(x==1) break;              
if(x==2 && y==1) break z;
o = o + x + y;
}        
}        
System.out.println(o);
}

What is the result when the go() method is invoked?
: go() 메소드를 호출하였을 때, 결과는 무엇인가?

A. 00
B. 0001
C. 000120
D. 00012021
E. Compilation fails.
F. An exception is thrown at runtime.

Answer: C


QUESTION 33
Given:
33. try {
34.  //some code here
35. } catch (NullPointerException e1) {
36.     System.out.print("a");
37. } catch (Exception e2) {
38.     System.out.print("b");
39. } finally {
40.     System.out.print("c");
41. }

If some sort of exception is thrown at line 34, which output is possible?
: 만약 예외의 어떤 종류가 34라인에서 발생한다면, 어느 출력물이 가능한가?

A. a
B. b
C. c
D. ac
E. abc

Answer: D


QUESTION 34
Given:

31. //some code here
32. try {
33.  //some code here
34. } catch (NullPointerException e1) {
35.  //some code here
36. } finally {
37.  //some code here
38. }

Under which three circumstances will the code on line 37 be executed? (Choose three.)
: 아래 3가지 상황 중 37라인의 코드가 실행되도록 하는 것은?

A. The instance gets garbage collected.
B. The code on line 33 throws an exception.
C. The code on line 35 throws an exception.
D. The code on line 31 throws an exception.
E. The code on line 33 executes successfully.

Answer: BCE


QUESTION 35
Given:

public class Donkey {
     public static void main(String[] args) {
boolean assertsOn = true;
assert (assertsOn) : assertsOn = true;
if(assertsOn) {
System.out.println("assert is on");
}    
}
}

If class Donkey is invoked twice, the first time without assertions enabled, and the second time with assertions enabled, what are the results?
: Donkey 클래스가 두번 호출된다면, 처음에는 assertions를 사용하지 않고, 두번째에는 assertions를 사용한다면, 결과는 무엇인가?

A. no output
B. no output assert is on
C. assert is on
D. no output An AssertionError is thrown.
E. assert is on An AssertionError is thrown.

Answer: C


QUESTION 36
Given:

public void method() {    
A a = new A();    
a.method1();
}

Which statement is true if a TestException is thrown on line 3 of class B?
: TestException가 B 클래스의 3라인에서 발생하는 경우 어떤 문장이 사실인가?

1. public class A{
2.     public void method1() {
3.         try {
4.             B b = new B();
5.             b.method2();
6.             //more code here
7.         } catch (TestException te){
8.             throw new RuntimeException(te);
9.         }
10.     }
11. }

1. public class B{
2.     public void method2() throws TestException {
3.         //more code here
4.     }
5. }
1. class TestException extends Exception {    
2. }  

A. Line 33 must be called within a try block.
B. The exception thrown by method1 in class A is not required to be caught.
C. The method declared on line 31 must be declared to throw a RuntimeException.
D. On line 5 of class A, the call to method2 of class B does not need to be placed in a try/catch block.
 
Answer: B


QUESTION 37
Given:

01. Float pi = new Float(3.14f);
02. if (pi > 3) {
03.     System.out.print("pi is bigger than 3. ");
04. }
05. else {
06.     System.out.print("pi is not bigger than 3. ");
07. }
08. finally {
09.     System.out.println("Have a nice day.");
10. }

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

A. Compilation fails.
B. pi is bigger than 3.
C. An exception occurs at runtime.
D. pi is bigger than 3. Have a nice day.
E. pi is not bigger than 3. Have a nice day.

Answer: A


QUESTION 38
Given:

1. public class Boxer1{
2.     Integer i;
3.     int x;
4.     public Boxer1(int y) {
5.         x = i+y;
6.         System.out.println(x);
7.     }
8.     public static void main(String[] args) {
9.         new Boxer1(new Integer(4));
10.     }
11. }

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

A. The value 4 is printed at the command line.
B. Compilation fails because of an error in line 5.
C. Compilation fails because of an error in line 9.
D. A NullPointerException occurs at runtime.
E. A NumberFormatException occurs at runtime.
F. An IllegalStateException occurs at runtime.

Answer: D


QUESTION 39
Given:

1. public class Person {
2.     private String name;
3.     public Person(String name) { this.name = name; }
4.     public boolean equals(Person p) {
5.         return p.name.equals(this.name);
6.     }
7. }

Which statement is true?

A. The equals method does NOT properly override the Object.equals method.
: equals method는 Object.equals 메소드를 정확하게 오버라이드하지 않는다.
B. Compilation fails because the private attribute p.name cannot be accessed in line 5.
C. To work correctly with hash-based data structures, this class must also implement the hashCode method. D. When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.

Answer: A


QUESTION 40
Which two statements are true about the hashCode method? (Choose two.)
: hashCode 메소드에 대한 사실인 두 문장은 어느 것인가? (두개 고르시오.)

A. The hashCode method for a given class can be used to test for object equality and object inequality for that class.
: 주어진 클래스의 hashCode 메소드는 해당 클래스의 객체 평등과 개체 불평등을 테스트하는 데 사용할 수 있습니다.
B. The hashCode method is used by the java.util.SortedSet collection class to order the elements within that set.
: hashCode 메소드는 세트 내의 요소를 명령하는 java.util.SortedSet 컬렉션 클래스에 의해 사용된다.
C. The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class.
: 주어진 클래스의 hashCode 메소드는 객체 불평등을 테스트하는 데 사용할 수 있지만, 객체 평등은 클래스에서 하지 못한다.
D. The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution.
: 해시 코드 메소드에 의해 반환되는 값의 유일한 중요한 특징은 값의 분포가 가우시안 분포를 수행해야한다는 것입니다.
E. The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.
: hashCode 메소드는 빠른 검색을 위해 해시 버킷에 그룹으로는 java.util.HashSet 컬렉션 클래스에 의해 해당 세트 내의 요소를 사용합니다.

 
Answer: CE

이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
What are the tourist attractions in this city?
: 이 도시의 관광 명소에는 어떤 것이 있어요?
You should go to Disneyland.
: 디즈니랜드는 꼭 가 보세요.

댓글 없음:

댓글 쓰기

대항해시대 조선 랭작

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