nerdexam
Oracle

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…

Exceptions and Assertions

Question

Given:

What is the result?

Exhibit

1Z0-804 question #134 exhibit

Options

  • A1
  • B0
  • C2
  • DCompilation fails
  • EAn exception is thrown at runtime

How the community answered

(26 responses)
  • B
    12% (3)
  • C
    4% (1)
  • D
    4% (1)
  • E
    81% (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

#runtime exception#exception handling#stack execution

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice