1Z0-804 · Question #134
Given: What is the result?
The correct answer is E. An exception is thrown at runtime. The code compiles fine. java.lang.NullPointerException because only one element of list is initialized : element [0] elements [1] and [2] equals null An exception is thrown at runtime due to data type comparison mismatch: Exception in thread "main" java.lang.ClassCastException…
Question
Given:
What is the result?
Exhibit
Options
- A1
- B0
- C2
- DCompilation fails
- EAn exception is thrown at runtime
How the community answered
(26 responses)- B12% (3)
- C4% (1)
- D4% (1)
- E81% (21)
Explanation
The code compiles fine. java.lang.NullPointerException because only one element of list is initialized : element [0] elements [1] and [2] equals null An exception is thrown at runtime due to data type comparison mismatch: Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at java.lang.Integer.compareTo(Integer.java:52) at java.util.Arrays.binarySearch0(Arrays.java:1481) at java.util.Arrays.binarySearch(Arrays.java:1423) at searchtext.SearchText.main(SearchText.java:22) Note:binarySearch public static int binarySearch(char[] a, char key)Searches the specified array of chars for the specified value using the binary search algorithm. The array mustbe sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. Ifthe array contains multiple elements with the specified value, there is no guarantee which one will be found. a - the array to be searched. key - the value to be searched for. Indexof the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertionpoint is defined as the point at which the key would be inserted into the list: the index of the first elementgreater than the key, or list.size(), if all elements in the list are less than the specified key. Note that thisguarantees that the return value will be >= 0 if and only if the key is
Topics
Community Discussion
No community discussion yet for this question.
