QUESTION 11
Given:
3. import java.util.*;
4. public class G1 {
5. public void takeList(List<? extends String> list) {
6. // insert code here 7. }
8. }
Which three code fragments, inserted independently at line 6, will compile? (Choose three.)
A. list.add("foo");
B. Object o = list;
C. String s = list.get(0);
D. list = new ArrayList<String>();
E. list = new ArrayList<Object>();
Correct Answer: BCD Section: All Explanation
Explanation/Reference:
QUESTION 12
Given that the elements of a PriorityQueue are ordered according to natural ordering, and:
import java.util.*;
public class GetInLine {
public static void main(String[] args) { PriorityQueue<String> pq = new PriorityQueue<String>(); pq.add("banana");
pq.add("pear");
pq.add("apple");
System.out.println(pq.poll() + " " + pq.peek());
}
}
What is the result?
A. apple pear
B. banana pear
C. apple apple
D. apple banana
E. banana banana
Correct Answer: D Section: All Explanation
Explanation/Reference:
QUESTION 13
Given:
enum Example { ONE, TWO, THREE }
Which statement is true?
A. The expressions (ONE == ONE) and ONE.equals(ONE) are both guaranteed to be true.
B. The expression (ONE < TWO) is guaranteed to be true and ONE.compareTo(TWO) is guaranteed to be less than one.
C. The Example values cannot be used in a raw java.util.HashMap; instead, the programmer must use a java.util.EnumMap.
D. The Example values can be used in a java.util.SortedSet, but the set will NOT be sorted because enumerated types do NOT implement java.lang.Comparable.
Correct Answer: A Section: All Explanation
Explanation/Reference:
QUESTION 14
Given:
import java.util.*;
public class Mapit {
public static void main(String[] args) { Set<Integer> set = new HashSet<Integer>(); Integer i1 = 45;
Integer i2 = 46; set.add(i1);
set.add(i1);
set.add(i2); System.out.print(set.size() + " "); set.remove(i1); System.out.print(set.size() + " "); i2 = 47;
set.remove(i2); System.out.print(set.size() + " ");
}
}
What is the result?
A. 2 1 0
B. 2 1 1
C. 3 2 1
D. 3 2 2
E. Compilation fails.
F. An exception is thrown at runtime.
Correct Answer: B Section: All Explanation
Explanation/Reference:
QUESTION 15
Given:
import java.util.*;
public class Explorer1 {
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(609);
System.out.println(s + " " + subs);
}
}
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. [608, 609, 610, 612] [608, 610]
D. [608, 609, 610, 612] [608, 609, 610]
E. [606, 608, 609, 610, 612] [608, 610]
F. [606, 608, 609, 610, 612] [608, 609, 610]
Correct Answer: F Section: All Explanation
Explanation/Reference:
QUESTION 16
Given:
import java.util.*;
public class Quest {
public static void main(String[] args) {
String[] colors = {"blue", "red", "green", "yellow", "orange"}; Arrays.sort(colors);
int s2 = Arrays.binarySearch(colors, "orange"); int s3 = Arrays.binarySearch(colors, "violet"); System.out.println(s2 + " " + s3);
}
}
What is the result?
A. 2 -1
B. 2 -4
C. 2 -5
D. 3 -1
E. 3 -4
F. 3 -5
G. Compilation fails.
H. An exception is thrown at runtime.
Correct Answer: C Section: All Explanation
Explanation/Reference:
public static int binarySearch(Object[] a, Object key)
Searches the specified array for the specified object using the binary search algorithm. The array must be sorted into ascending order according to the natural ordering of its elements (as by the sort(Object[]) method) prior to making this call. If it is not sorted, the results are undefined. (If the array contains elements that are not mutually comparable (for example, strings and integers), it cannot be sorted according to the natural ordering of its elements, hence results are undefined.) If the array contains multiple elements equal to the specified object, there is no guarantee which one will be found.
Parameters:
a - the array to be searched
key - the value to be searched for
Returns:
index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
Throws:
ClassCastException - if the search key is not comparable to the elements of the array.
QUESTION 17
Given:
34. HashMap props = new HashMap();
35. props.put("key45", "some value");
36. props.put("key12", "some other value");
37. props.put("key39", "yet another value");
38. Set s = props.keySet();
39. //insert code here
What, inserted at line 39, will sort the keys in the props HashMap?
A. Arrays.sort(s);
B. s = new TreeSet(s);
C. Collections.sort(s);
D. s = new SortedSet(s);
Correct Answer: B Section: All Explanation
Explanation/Reference:
QUESTION 18
Which two statements are true? (Choose two.)
A. It is possible to synchronize static methods.
B. When a thread has yielded as a result of yield(), it releases its locks.
C. When a thread is sleeping as a result of sleep(), it releases its locks.
D. The Object.wait() method can be invoked only from a synchronized context.
E. The Thread.sleep() method can be invoked only from a synchronized context.
F. When the thread scheduler receives a notify() request, and notifies a thread, that thread immediately releases its lock.
Correct Answer: AD Section: All Explanation
Explanation/Reference:
QUESTION 19
Given:
public class TestOne implements Runnable {
public static void main (String[] args) throws Exception { Thread t = new Thread(new TestOne());
t.start(); System.out.print("Started"); t.join(); System.out.print("Complete");
}
public void run() {
for (int i = 0; i < 4; i++) { System.out.print(i);
}
}
}
What can be a result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes and prints "StartedComplete".
D. The code executes and prints "StartedComplete0123".
E. The code executes and prints "Started0123Complete".
Correct Answer: E Section: All Explanation
Explanation/Reference:
QUESTION 20
Which three will compile and run without exception? (Choose three.)
A. private synchronized Object o;
B. void go() {
synchronized() { /* code here */ }
}
C. public synchronized void go() { /* code here */ }
D. private synchronized(this) void go() { /* code here */ }
E. void go() {
synchronized(Object.class) { /* code here */ }
}
F. void go() {
Object o = new Object(); synchronized(o) { /* code here */ }
}
Correct Answer: CEF Section: All Explanation
Explanation/Reference:
Source from : Oracle.Exactexams.1z0-851.v2013-11-27.by.SomeBody ().pdf
'Certificate > OCAJP' 카테고리의 다른 글
[1Z0-851B] Question 51~60 (0) | 2017.08.11 |
---|---|
[1Z0-851B] Question 41~50 (0) | 2017.08.11 |
[1Z0-851B] Question 31~40 (0) | 2017.08.11 |
[1Z0-851B] Question 21~30 (0) | 2017.08.11 |
[1Z0-851B] Question 01~10 (0) | 2017.08.11 |
[1Z0-851A] Question 51~60 (0) | 2017.08.05 |
[1Z0-851A] Question 41~50 (0) | 2017.08.05 |
[1Z0-851A] Question 31~40 (0) | 2017.08.05 |