Question #146459

What is the output after executing the following code fragment: int [] x = {1,2,3,4,5}; System.out.println(x[0])
a.Array Index Out Of Bounds Exception
b.2
c.6
d.1

Expert's answer

Here, we declare and initialize the array using array literal notation. We can access an array element by referring to the index number. Since, the array indexes begins with 0, x[0] is the first element of this array. Therefore, the output after executing the following code fragment will be 1.

Answer:

d. 1


LATEST TUTORIALS
APPROVED BY CLIENTS