The statements string var1[ ]; var1 = new string[3];…

2018

The statements

string var1[ ];

var1 = new string[3];

system.out.println(var1[1]);

print

  1. A.

    an empty string

  2. B.

    null

  3. C.

    0

  4. 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.

Explore the full course: Dsssb Tgt Computer Science Paper 2