카테고리 없음
OCJP Study 05
Soul-Learner
2013. 12. 26. 20:06
OCJP(Java 6) 기출문제 연습 5(41~50)
PC나 스마트폰에서도 동일하게 실행되므로 장소를 가리지 않고 OCJP(JAVA 6) 국제 자격증을 목표로 학습할 수 있다.
QUESTION 41
Given:
int x = 0;
int y = 10;
do {
y--;
++x;
} while (x < 5);
System.out.print(x + "," + y);
What is the result?
Given:
int x = 0;
int y = 10;
do {
y--;
++x;
} while (x < 5);
System.out.print(x + "," + y);
What is the result?
B
설명없음
QUESTION 42
Given:
public class Donkey2 {
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?
Given:
public class Donkey2 {
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?
C
설명없음
QUESTION 43
Click the Exhibit button.
Given:
public void method() {
Aa= new A();
a.method1();
}
Which statement is true if a TestException is thrown on line 3 of class B?
1. public class A{
2. public void method1() {
3. try {
4.
Bb= 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. }
Click the Exhibit button.
Given:
public void method() {
Aa= new A();
a.method1();
}
Which statement is true if a TestException is thrown on line 3 of class B?
1. public class A{
2. public void method1() {
3. try {
4.
Bb= 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. }
B
설명없음
QUESTION 44
Given:
Float pi = new Float(3.14f);
if (pi > 3) {
System.out.print("pi is bigger than 3. ");
}
else {
System.out.print("pi is not bigger than 3. ");
}
finally {
System.out.println("Have a nice day.");
}
What is the result?
Given:
Float pi = new Float(3.14f);
if (pi > 3) {
System.out.print("pi is bigger than 3. ");
}
else {
System.out.print("pi is not bigger than 3. ");
}
finally {
System.out.println("Have a nice day.");
}
What is the result?
A
설명없음
QUESTION 45
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?
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?
D
설명없음
QUESTION 46
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?
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
설명없음
QUESTION 47
Which two statements are true about the hashCode method? (Choose two.)
Which two statements are true about the hashCode method? (Choose two.)
C,E
설명없음
QUESTION 48
Given a pre-generics implementation of a method:
11. public static int sum(List list) {
12. int sum = 0;
13. for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
14. int i = ((Integer)iter.next()).intValue();
15. sum += i;
16. }
17. return sum;
18. }
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
Given a pre-generics implementation of a method:
11. public static int sum(List list) {
12. int sum = 0;
13. for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
14. int i = ((Integer)iter.next()).intValue();
15. sum += i;
16. }
17. return sum;
18. }
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
A,C,F
설명없음
QUESTION 49
Given:
23. Object [] myObjects = {
24. new Integer(12),
25. new String("foo"),
26. new Integer(5),
27. new Boolean(true)
28. };
29. Arrays.sort(myObjects);
30. for(int i=0; i<myobjects.length; i++){
31. System.out.print(myObjects[i].toString());
32. System.out.print(" ");
33. }
What is the result?
Given:
23. Object [] myObjects = {
24. new Integer(12),
25. new String("foo"),
26. new Integer(5),
27. new Boolean(true)
28. };
29. Arrays.sort(myObjects);
30. for(int i=0; i<myobjects.length; i++){
31. System.out.print(myObjects[i].toString());
32. System.out.print(" ");
33. }
What is the result?
C
설명없음
QUESTION 50
Given a class Repetition:
1. package utils;
2.
3. public class Repetition {
4. public static String twice(String s) { return s + s; }
5. }
and given another class Demo:
1. public class Demo {
2. public static void main(String[] args) {
3. System.out.println(twice("pizza"));
4. }
5. }
Which code should be inserted at line 1 of Demo.java to compile and run Demo to print "pizzapizza"?
Given a class Repetition:
1. package utils;
2.
3. public class Repetition {
4. public static String twice(String s) { return s + s; }
5. }
and given another class Demo:
1. public class Demo {
2. public static void main(String[] args) {
3. System.out.println(twice("pizza"));
4. }
5. }
Which code should be inserted at line 1 of Demo.java to compile and run Demo to print "pizzapizza"?
F
설명없음