Question:

Which of the following refer to the starting index value in arrays of Java program?

Show Hint

Java arrays always begin with index {0}, which is called zero-based indexing.
  • 0
  • 1
  • null
  • -1
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Understanding arrays in Java.

An array in Java is a data structure that stores multiple values of the same type in a single variable. Each value in the array is stored in a specific position known as an index.

Step 2: Indexing in arrays.

Java uses zero-based indexing. This means that the first element of an array is stored at index position 0. The second element is stored at index 1, and so on.

Example:

int arr[] = {10, 20, 30};
Here:

arr[0] = 10
arr[1] = 20
arr[2] = 30

Step 3: Evaluation of options.

(A) 0: Correct. Arrays in Java start from index 0.

(B) 1: Incorrect. Java does not use 1-based indexing.

(C) null: Incorrect. Null represents absence of value, not index.

(D) -1: Incorrect. Negative indices are not valid in Java arrays.

Step 4: Conclusion.

Thus, the starting index value in Java arrays is 0.

Final Answer: 0
Was this answer helpful?
0
0