QUESTION 31
Given:
public class Person {
private name;
public Person(String name) {
this.name = name;
}
public int hashCode() {
return 420;
}
}
Which statement is true?
A. The time to find the value from HashMap with a Person key depends on the size of the map.
B. Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.
C. Inserting a second Person object into a HashSet will cause the first Person object to be removed as a duplicate.
D. The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.
Correct Answer: A Section: All Explanation
Explanation/Reference:
QUESTION 32
Given:
import java.util.TreeSet;
public class Explorer2 {
public static void main(String[] args) { TreeSet<Integer> s = new TreeSet<Integer>(); TreeSet<Integer> subs = new TreeSet<Integer>(); for(int i = 606; i < 613; i++)
if(i%2 == 0) s.add(i);
subs = (TreeSet)s.subSet(608, true, 611, true); s.add(629);
System.out.println(s + " " + subs);
}
}
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]
Correct Answer: E
Section: All Explanation
Explanation/Reference:
QUESTION 33
Given:
public class Drink implements Comparable {
public String name;
public int compareTo(Object o) {
return 0;
}
}
and:
Drink one = new Drink(); Drink two = new Drink(); one.name= "Coffee"; two.name= "Tea";
TreeSet set = new TreeSet(); set.add(one);
set.add(two);
A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?
A. Tea
B. Coffee
C. Coffee Tea
D. Compilation fails.
E. The code runs with no output.
F. An exception is thrown at runtime.
Correct Answer: B Section: All Explanation
Explanation/Reference:
QUESTION 34
A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?
A. class MinMax<E extends Comparable<E>> { E min = null;
E max = null; public MinMax() {}
public void put(E value) { /* store min or max */ }
}
B. class MinMax<E implements Comparable<E>> { E min = null;
E max = null; public MinMax() {}
public void put(E value) { /* store min or max */ }
}
C. class MinMax<E extends Comparable<E>> {
<E> E min = null;
<E> E max = null; public MinMax() {}
public <E> void put(E value) { /* store min or max */ }
}
D. class MinMax<E implements Comparable<E>> {
<E> E min = null;
<E> E max = null; public MinMax() {}
public <E> void put(E value) { /* store min or max */ }
}
Correct Answer: A Section: All Explanation
Explanation/Reference:
QUESTION 35
Given:
1. import java.util.*;
2. public class Example {
3. public static void main(String[] args) {
4. // insert code here
5. set.add(new Integer(2));
6. set.add(new Integer(1));
7. System.out.println(set);
08. }
09. }
Which code, inserted at line 4, guarantees that this program will output [1, 2]?
A. Set set = new TreeSet();
B. Set set = new HashSet();
C. Set set = new SortedSet();
D. List set = new SortedList();
E. Set set = new LinkedHashSet();
Correct Answer: A Section: All Explanation
Explanation/Reference:
QUESTION 36
Given:
5. class A {
6. void foo() throws Exception { throw new Exception(); }
07. }
8. class SubB2 extends A {
9. void foo() { System.out.println("B "); }
10. }
11. class Tester {
12. public static void main(String[] args) {
13. A a = new SubB2();
14. a.foo();
15. }
16. }
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 14.
E. An Exception is thrown with no other output.
Correct Answer: D Section: All Explanation
Explanation/Reference:
Unhandled exception type Exception
QUESTION 37
Given:
84. try {
85. ResourceConnection con = resourceFactory.getConnection();
86. Results r = con.query("GET INFO FROM CUSTOMER");
87. info = r.getData();
88. con.close();
89. } catch (ResourceException re) {
90. errorLog.write(re.getMessage());
91. }
92. return info;
Which statement is true if a ResourceException is thrown on line 86?
A. Line 92 will not execute.
B. The connection will not be retrieved in line 85.
C. The resource connection will not be closed on line 88.
D. The enclosing method will throw an exception to its caller.
Correct Answer: C Section: All Explanation
Explanation/Reference:
QUESTION 38
Given:
public class Breaker {
static String o = "";
public static void main(String[] args) { z: o = o + 2;
for (int x = 3; x < 8; x++) {
if (x == 4)
break; if (x == 6)
break z;
o = o + x;
}
System.out.println(o);
}
}
What is the result?
A. 23
B. 234
C. 235
D. 2345
E. 2357
F. 23457
G. Compilation fails.
Correct Answer: G Section: All Explanation
Explanation/Reference:
Label placed incorrectly.
QUESTION 39
Given:
11. public void go(int x) {
12. assert (x > 0);
13. switch(x) {
14. case 2: ;
15. default: assert false;
16. }
17. }
18. private void go2(int x) { assert (x < 0); }
Which statement is true?
A. All of the assert statements are used appropriately.
B. Only the assert statement on line 12 is used appropriately.
C. Only the assert statement on line 15 is used appropriately.
D. Only the assert statement on line 18 is used appropriately.
E. Only the assert statements on lines 12 and 15 are used appropriately.
F. Only the assert statements on lines 12 and 18 are used appropriately.
G. Only the assert statements on lines 15 and 18 are used appropriately.
Correct Answer: G Section: All Explanation
Explanation/Reference:
QUESTION 40
Given:
public static void main(String[] args) {
try {
args = null; args[0] = "test";
System.out.println(args[0]);
} catch (Exception ex) { System.out.println("Exception");
} catch (NullPointerException npe) { System.out.println("NullPointerException");
}
}
What is the result?
A. test
B. Exception
C. Compilation fails.
D. NullPointerException
Correct Answer: C Section: All Explanation
Explanation/Reference:
Incorrect order of catch statements.
Source from : Oracle.Exactexams.1z0-851.v2013-11-27.by.SomeBody ().pdf
'Certificate > OCAJP' 카테고리의 다른 글
[1Z0-851D] Question 11~20 (0) | 2017.08.13 |
---|---|
[1Z0-851D] Question 01~10 (0) | 2017.08.13 |
[1Z0-851C] Question 51~60 (0) | 2017.08.12 |
[1Z0-851C] Question 41~50 (0) | 2017.08.12 |
[1Z0-851C] Question 21~30 (0) | 2017.08.12 |
[1Z0-851C] Question 11~20 (0) | 2017.08.12 |
[1Z0-851C] Question 01~10 (0) | 2017.08.12 |
[1Z0-851B] Question 51~60 (0) | 2017.08.11 |