What will the following code snippet print?
int index = 1; String [] strArr = new String [5]; String myStr = strArr [index]; System.out.println(myStr);
Select 1 option
ArrayIndexOutOfBounds
at runtime. Correct Option is : B
When you create an array of Objects (here, Strings) all the elements are initialized to null.
So in the line 3, null is assigned to myStr
.
Note that. empty string is "" (String str = "";) and is not same as null.