To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) Arrays in Java are essentially objects - This option is correct because arrays in Java are indeed objects. In Java, arrays are a special type of object that can hold a fixed number of elements of the same type.
Option B) It is not possible to assign one array to another. Individual elements of the array can, however, be assigned - This option is incorrect. In Java, it is possible to assign one array to another using the assignment operator. For example: int[] array1 = {1, 2, 3}; int[] array2 = array1;
. This assigns array1
to array2
, meaning both arrays now refer to the same memory location.
Option C) Array elements are indexed from 1 to the size of the array - This option is incorrect. In Java, array elements are indexed from 0 to size-1
. The first element of an array is accessed using the index 0, not 1.
Option D) If a method tries to access an array element beyond its range, a compile warning is generated - This option is incorrect. In Java, if a method tries to access an array element beyond its range, it will not generate a compile warning. Instead, it will throw an ArrayIndexOutOfBoundsException
at runtime.
The correct answer is A) Arrays in Java are essentially objects. This option is correct because arrays in Java are objects.