카테고리 없음
OCJP Study 22
Soul-Learner
2013. 12. 31. 17:05
OCJP(Java 6) 기출문제 연습 22(211~220)
PC나 스마트폰에서도 동일하게 실행되므로 장소를 가리지 않고 OCJP(JAVA 6) 국제 자격증을 목표로 학습할 수 있다.
QUESTION 211
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.)
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,C
설명없음
QUESTION 212
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?
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
설명없음
QUESTION 213
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?
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
Error msg: "Cannot override the final method from Pizza" on the line "public void addTopping
(String topping) {" from the class PepperoniPizza
ZZZ
ZZZ
QUESTION 214
Which three statements are true? (Choose three.)
Which three statements are true? (Choose three.)
B,E,F
설명없음
QUESTION 215
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.)
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.)
D,E
설명없음
QUESTION 216
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?
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?
D
설명없음
QUESTION 217
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?
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?
B
설명없음
QUESTION 218
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.)
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,D
설명없음
QUESTION 219
Given:
import java.util.*;
public class Hancock {
// insert code here Linea 5
list.add("foo");
}
}
Which two code fragments, inserted independently at line 5, will compile without warnings? (Choose two.)
Given:
import java.util.*;
public class Hancock {
// insert code here Linea 5
list.add("foo");
}
}
Which two code fragments, inserted independently at line 5, will compile without warnings? (Choose two.)
B,C
설명없음
QUESTION 220
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 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?
D
설명없음