nerdexam
Oracle

1Z0-803 · Question #246

Given: public class Test { public static void main(String[] args) { try { String[] arr =new String[4]; arr[1] = "Unix"; arr[2] = "Linux"; arr[3] = "Solarios"; for (String var : arr) { System.out.print

The correct answer is B. Null Unix Linux Solaris. null Unix Linux Solarios The first element, arr[0], has not been defined.

Creating and Using Arrays

Question

Given:

public class Test { public static void main(String[] args) { try { String[] arr =new String[4]; arr[1] = "Unix"; arr[2] = "Linux"; arr[3] = "Solarios"; for (String var : arr) { System.out.print(var + " "); } } catch(Exception e) { System.out.print (e.getClass()); } } } What is the result?

Options

  • AUnix Linux Solaris
  • BNull Unix Linux Solaris
  • CClass java.lang.Exception
  • DClass java.lang.NullPointerException

How the community answered

(38 responses)
  • A
    3% (1)
  • B
    79% (30)
  • C
    8% (3)
  • D
    11% (4)

Explanation

null Unix Linux Solarios The first element, arr[0], has not been defined.

Topics

#arrays#default values#enhanced for loop#exception handling

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice