The statements string var1[ ]; var1 = new string[3];…
2018
The statements
string var1[ ];
var1 = new string[3];
system.out.println(var1[1]);
- A.
an empty string
- B.
null
- C.
0
- D.
a garbage character
Attempted by 75 students.
Show answer & explanation
Correct answer: B
The Correct Option is: Option 2 (null)
In Java, when you initialize an array of objects (and String is an object, not a primitive type), the elements of the array are automatically initialized to their default value. For any reference type (Object), the default value is null. Since var1 = new String[3]; creates the array but does not assign specific strings to the indices, var1[1] is null.