OCJP(Java 6) 기출문제 연습 21(201~210)
PC나 스마트폰에서도 동일하게 실행되므로 장소를 가리지 않고 OCJP(JAVA 6) 국제 자격증을 목표로 학습할 수 있다.
QUESTION 201
Given:
11. String test = "This is a test";
12. String[] tokens = test.split("\s");
13. System.out.println(tokens.length);
What is the result?
Given:
11. String test = "This is a test";
12. String[] tokens = test.split("\s");
13. System.out.println(tokens.length);
What is the result?
D
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
QUESTION 202
Given:
import java.io.*;
class Animal {
Animal() {
System.out.print("a");
}
}
class Dog extends Animal implements Serializable {
Dog() {
System.out.print("d");
}
}
public class Beagle extends Dog {
}
If an instance of class Beagle is created, then Serialized, then deSerialized, what is the result?
Given:
import java.io.*;
class Animal {
Animal() {
System.out.print("a");
}
}
class Dog extends Animal implements Serializable {
Dog() {
System.out.print("d");
}
}
public class Beagle extends Dog {
}
If an instance of class Beagle is created, then Serialized, then deSerialized, what is the result?
B
설명없음
QUESTION 203
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?
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?
B
설명없음
QUESTION 204
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 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?
E
설명없음
QUESTION 205
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?
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?
D
설명없음
QUESTION 206
Given:
class Alpha {
public void foo() { System.out.print("Afoo "); }
}
public class Beta extends Alpha {
public void foo() { System.out.print("Bfoo "); }
public static void main(String[] args) {
Alpha a = new Beta();
Beta b = (Beta)a;
a.foo();
b.foo();
}
}
What is the result?
class Alpha {
public void foo() { System.out.print("Afoo "); }
}
public class Beta extends Alpha {
public void foo() { System.out.print("Bfoo "); }
public static void main(String[] args) {
Alpha a = new Beta();
Beta b = (Beta)a;
a.foo();
b.foo();
}
}
What is the result?
D
설명없음
QUESTION 207
Given:
1. public class Target {
2. private int i = 0;
3. public int addOne() {
4. return ++i;
5. }
6. }
And:
1. public class Client {
2. public static void main(String[] args){
3. System.out.println(new Target().addOne());
4. }
5. }
Which change can you make to Target without affecting Client?
Given:
1. public class Target {
2. private int i = 0;
3. public int addOne() {
4. return ++i;
5. }
6. }
And:
1. public class Client {
2. public static void main(String[] args){
3. System.out.println(new Target().addOne());
4. }
5. }
Which change can you make to Target without affecting Client?
D
설명없음
QUESTION 208
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?
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?
E
Exception in thread "main" java.lang.ClassCastException: Dog cannot be cast to Cat
at Client.main(Client.java:12)
at Client.main(Client.java:12)
QUESTION 209
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.)
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.)
A,B,D,F
설명없음
QUESTION 210
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.)
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.)
A,E
설명없음