5. Arrays in Java
Which of the following statements are true?
Pick ONE option
Arrays in java are essentially coeds.
is not possible to assign one array to another. Andindual elements of array can honeter de
assigned
Array elements are indexed from 1 to size of array.
of a method tries to access an array element beyond its range, a compile warning is generated
Answers
Answer : (1) Arrays in java are essentially objects.
Concept : Arrays in Java
Given : (1)Arrays in java are essentially objects.
(2) It is not possible to assign one array to another. An individual
elements of array can however be assigned.
(3) Array elements are indexed from 1 to size of array.
(4) If a method tries to access an array element beyond its range,
a compile warning is generated
To Find : Which of the following statements are true ?
Explanation :
Arrays in java are essentially objects. These contains elements of similar data type and the elements in an array are stored in contiguous memory location. Hence, option (1) is the correct statement.
In Java, one array can be assigned to another array. Individual elements of an array can also be assigned. Hence, option (2) is incorrect.
Array elements in Java are indexed from 0 to the ( length of array - 1). Array index does not start from 1 in Java. Hence, option (3) is also incorrect.
If a method tries to access an element in array beyond its range, it does not give a compilation error or it does not generate a compile warning. Hence, option (4) is also incorrect.
#SPJ3