Name : OCJP Study
Category : Software
Purpose : JAVA 공부하면서 OCJP 가 합격이 되도록 비나이다.
compatibility : ...
Etc : eclipse
공부한 거는 Post 하자.!!!
JAVA도 공부하면서 OCJP 도 한번에 합격하시기를...
지금 이글을 읽을 정도로 자신의 시간을 투자하는 사람이라면 합격은 당연한것인가. 흠.
그럼 시작.
QUESTION 21
Given:
class Animal {
public String noise() {
return "peep";
}
}
class Dog extends Animal {
public String noise() {
return "bark";
}
}
class Cat extends Animal {
public String noise() {
return "meow";
}
}
...
30. Animal animal = new Dog();
31. Cat cat = (Cat)animal;
32. System.out.println(cat.noise());
What is the result?
: 결과는 무엇인가?
A. peep
B. bark
C. meow
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: E
QUESTION 22
Given:
abstract class A {
abstract void a1();
void a2() {
}
}
class B extends A {
void a1() {
}
void a2() {
}
}
class C extends B {
void c1() {
}
}
And:
A x = new B();
C y = new C();
A z = new C();
What are four valid examples of polymorphic method calls? (Choose four.)
: 다형성 메소드 호출의 유효한 예 4개는 무엇인가? (4개를 고르시오.)
A. x.a2();
B. z.a2();
C. z.c1();
D. z.a1();
E. y.c1();
F. x.a1();
Answer: ABDF
QUESTION 23
Given:
class Employee {
String name;
double baseSalary;
Employee(String name, double baseSalary) {
this.name = name;
this.baseSalary = baseSalary;
}
}
public class SalesPerson extends Employee {
double commission;
public SalesPerson(String name, double baseSalary, double commission) {
// insert code here Line 13
}
}
Which two code fragments, inserted independently at line 13, will compile? (Choose two.)
: 13라인에 독립적으로 삽입하여 컴파일되는 코드 조각 2개는? (2개를 고르시오.)
A. super(name, baseSalary);
B. this.commission = commission;
C. super(); this.commission = commission;
D. this.commission = commission; super();
E. super(name, baseSalary); this.commission = commission;
F. this.commission = commission; super(name, baseSalary);
G. super(name, baseSalary, commission);
Answer: AE
QUESTION 24
A team of programmers is involved in reviewing a proposed design for a new utility class. After some discussion, they realize that the current design allows other classes to access methods in the utility class that should be accessible only to methods within the utility class itself.
What design issue has the team discovered?
: 어떤 디자인 문제점을 팀은 발견했는가?
A. Tight coupling
B. Low cohesion
C. High cohesion
D. Loose coupling
E. Weak encapsulation
F. Strong encapsulation
Answer: E
QUESTION 25
Given that:
Gadget has-a Sprocket and Gadget has-a Spring and Gadget is-a Widget and Widget has-a Sprocket Which two code fragments represent these relationships? (Choose two.)
A. class Widget {
Sprocket s;
}
class Gadget extends Widget {
Spring s;
}
B. class Widget {
}
class Gadget extends Widget {
Spring s1;
Sprocket s2;
}
C. class Widget {
Sprocket s1;
Spring s2;
}
class Gadget extends Widget {
}
D. class Gadget {
Spring s;
}
class Widget extends Gadget {
Sprocket s;
}
E. class Gadget {
}
class Widget extends Gadget {
Sprocket s1;
Spring s2;
}
F. class Gadget {
Spring s1;
Sprocket s2;
}
class Widget extends Gadget {
}
Answer: AC
QUESTION 26
Given:
class Pizza {
java.util.ArrayList toppings;
public final void addTopping(String topping) {
toppings.add(topping);
}
public void removeTopping(String topping) {
toppings.remove(topping);
}
}
public class PepperoniPizza extends Pizza {
public void addTopping(String topping) {
System.out.println("Cannot add Toppings");
}
public static void main(String[] args) {
Pizza pizza = new PepperoniPizza();
pizza.addTopping("Mushrooms");
pizza.removeTopping("Peperoni");
}
}
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. Cannot add Toppings
C. The code runs with no output.
D. A NullPointerException is thrown in Line 4.
Answer: A
QUESTION 27
Which three statements are true? (Choose three.)
: 사실인 세 문장은? (3개를 고르시오.)
A. A final method in class X can be abstract if and only if X is abstract.
B. A protected method in class X can be overridden by any subclass of X.
C. A private static method can be called only within other static methods in class X.
D. A non-static public final method in class X can be overridden in any subclass of X.
E. A public static method in class X can be called by a subclass of X without explicitly referencing the class X.
F. A method with the same signature as a private final method in class X can be implemented in a subclass of X.
G. A protected method in class X can be overridden by a subclass of X only if the subclass is in the same package as X.
Answer: BEF
QUESTION 28
Click the Exhibit button.
1. public class Car {
2. private int wheelCount;
3. private String vin;
4. public Car(String vin){
5. this.vin = vin;
6. this.wheelCount = 4;
7. }
8. public String drive(){
9. return "zoom-zoom";
10. }
11. public String getInfo() {
12. return "VIN: " + vin + " wheels: " + wheelCount;
13. }
14. }
And
1. public class MeGo extends Car {
2. public MeGo(String vin) {
3. this.wheelCount = 3;
4. }
5. }
What two must the programmer do to correct the compilation errors? (Choose two.)
: 프로그래머가 컴파일 오류를 수정하려면 어떤 두 개를 반드시 해야 하나? (2개를 고르시오.)
A. insert a call to this() in the Car constructor
B. insert a call to this() in the MeGo constructor
C. insert a call to super() in the MeGo constructor
D. insert a call to super(vin) in the MeGo constructor
E. change the wheelCount variable in Car to protected
F. change line 3 in the MeGo class to super.wheelCount = 3;
Answer: DE
QUESTION 29
Click the Exhibit button.
1. import java.util.*;
2. public class TestSet{
3. enum Example {ONE, TWO, THREE }
4. public static void main(String[] args) {
5. Collection coll = new ArrayList();
6. coll.add(Example.THREE);
7. coll.add(Example.THREE);
8. coll.add(Example.THREE);
9. coll.add(Example.TWO);
10. coll.add(Example.TWO);
11. coll.add(Example.ONE);
12. Set set = new HashSet(coll);
13. }
14. }
Which statement is true about the set variable on line 12?
: 12라인에 설정된 변수에 관련해서 사실인 문장은?
A. The set variable contains all six elements from the coll collection, and the order is guaranteed to be preserved.
B. The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved.
C. The set variable contains all six elements from the coll collection, but the order is NOT guaranteed to be preserved.
D. The set variable contains only three elements from the coll collection, but the order is NOT guaranteed to be preserved.
Answer: D
QUESTION 30
Given:
public class Person {
private String name, comment;
private int age;
public Person(String n, int a, String c) {
name = n;
age = a;
comment = c;
}
public boolean equals(Object o) {
if (!(o instanceof Person))
return false;
Person p = (Person) o;
return age == p.age && name.equals(p.name);
}
}
What is the appropriate definition of the hashCode method in class Person?
: Person 클래스의 hashCode 메소드의 적절한 정의는 무엇인가?
A. return super.hashCode();
B. return name.hashCode() + age * 7;
C. return name.hashCode() + comment.hashCode() / 2;
D. return name.hashCode() + comment.hashCode() / 2 - age * 3;
Answer: B
QUESTION 31
Given:
public class Key {
private long id1;
private long id2;
// class Key methods
}
A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key? (Choose two.)
A. public int hashCode()
B. public boolean equals(Key k)
C. public int compareTo(Object o)
D. public boolean equals(Object o)
E. public boolean compareTo(Key k)
Answer: AD
QUESTION 32
A programmer has an algorithm that requires a java.util.List that provides an efficient implementation of add(0, object), but does NOT need to support quick random access. What supports these requirements?
A. java.util.Queue
B. java.util.ArrayList
C. java.util.LinearList
D. java.util.LinkedList
Answer: D
QUESTION 33
Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true? (Choose two.)
A. The class implements java.lang.Comparable.
B. The class implements java.util.Comparator.
C. The interface used to implement sorting allows this class to define only one sort sequence.
D. The interface used to implement sorting allows this class to define many different sort sequences.
Answer: AC
QUESTION 34
Given:
1. import java.util.*;
2.
3. public class Explorer3 {
4. public static void main(String[] args) {
5. TreeSet<Integer> s = new TreeSet<Integer>();
6. TreeSet<Integer> subs = new TreeSet<Integer>();
7. for (int i = 606; i < 613; i++)
8. if (i % 2 == 0)
9. s.add(i);
10. subs = (TreeSet) s.subSet(608, true, 611, true);
11. subs.add(629);
12. System.out.println(s + " " + subs);
13. }
14. }
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. An exception is thrown at runtime.
C. [608, 610, 612, 629] [608, 610]
D. [608, 610, 612, 629] [608, 610, 629]
E. [606, 608, 610, 612, 629] [608, 610]
F. [606, 608, 610, 612, 629] [608, 610, 629]
Answer: B
QUESTION 35
Given:
1. import java.util.*;
2.
3. public class LetterASort {
4. public static void main(String[] args) {
5. ArrayList<String> strings = new ArrayList<String>();
6. strings.add("aAaA");
7. strings.add("AaA");
8. strings.add("aAa");
9. strings.add("AAaa");
10. Collections.sort(strings);
11. for (String s : strings) {
12. System.out.print(s + " ");
13. }
14. }
15. }
What is the result?
: 결과는 무엇인가?
A. Compilation fails.
B. aAaA aAa AAaa AaA
C. AAaa AaA aAa aAaA
D. AaA AAaa aAaA aAa
E. aAa AaA aAaA AAaa
F. An exception is thrown at runtime.
Answer: C
QUESTION 36
Given:
1. class A {
2. void foo() throws Exception {
3. throw new Exception();
4. }
5. }
6.
7. class SubB2 extends A {
8. void foo() {
9. System.out.println("B ");
10. }
11. }
12. class Tester {
13. public static void main(String[] args) {
14. A a = new SubB2();
15. a.foo();
16. }
17. }
What is the result?
: 결과는 무엇인가?
A. B B.
B, followed by an Exception.
C. Compilation fails due to an error on line 9.
D. Compilation fails due to an error on line 15.
E. An Exception is thrown with no other output
Answer: D
QUESTION 37
Given a method that must ensure that its parameter is not null:
11. public void someMethod(Object value) {
12. // check for null value
...
20. System.out.println(value.getClass());
21. }
What, inserted at line 12, is the appropriate way to handle a null value?
: 12라인에 삽입하여, null 값을 적절하게 처리할 수 있는 방법은 무엇인가?
A. assert value == null;
B. assert value != null, "value is null";
C. if (value == null) { throw new AssertionException("value is null"); }
D. if (value == null) { throw new IllegalArgumentException("value is null"); }
Answer: D
QUESTION 38
Given:
1. public class Mule {
2. public static void main(String[] args) {
3. boolean assert = true;
4. if(assert) {
5. System.out.println("assert is true");
6. }
7. }
8. }
Which command-line invocations will compile?
: 명령 라인을 호출하여 컴파일 되는 것은 어느 것인가?
A. javac Mule.java
B. javac -source 1.3 Mule.java
C. javac -source 1.4 Mule.java
D. javac -source 1.5 Mule.java
Answer: B
QUESTION 39
Click the Exhibit button
1. public class A {
2. public void method1(){
3. B b = new B();
4. b.method2();
5. // more code here
6. }
7. }
1. public class B{
2. public void method2() {
3. C c = new C();
4. c.method3();
5. // more code here
6. }
7. }
1. public class C {
2. public void method3(){
3. // more code here
4. }
5. }
Given:
25. try {
26. A a = new A();
27. a.method1();
28. } catch (Exception e) {
29. System.out.print("an error occurred");
30. }
Which two statements are true if a NullPointerException is thrown on line 3 of class C? (Choose two.)
: NullPointerException 이 C 클래스의 3라인에서 발생한다면 사실인 2 문장은? (2개를 고르시오.)
A. The application will crash.
B. The code on line 29 will be executed.
C. The code on line 5 of class A will execute.
D. The code on line 5 of class B will execute.
E. The exception will be propagated back to line 27.
Answer: BE
QUESTION 40
Given:
1. public class Venus {
2. public static void main(String[] args) {
3. int[] x = { 1, 2, 3 };
4. int y[] = { 4, 5, 6 };
5. new Venus().go(x, y);
6. }
7.
8. void go(int[]... z) {
9. for (int[] a : z)
10. System.out.print(a[0]);
11. }
12. }
What is the result?
: 결과는 무엇인가?
A. 1
B. 12
C. 14
D. 123
E. Compilation fails.
F. An exception is thrown at runtime.
Answer: C
이해가 안되는 문제가 있다면 글 남겨주세요. 저도 JAVA 공부하면서 같이 해결해요~
Today.
incompetent
aj.형용사 무능한
athletic
aj.형용사 (몸이) 탄탄한
bristle
n.명사 짧고 뻣뻣한 털
probable
aj.형용사 (어떤 일이) 있을 것 같은, 개연성 있는
in full swing
한창 진행 중인[무르익은]
댓글 없음:
댓글 쓰기