865 views
1 vote
Assume you have the following array: int[] values = new int[15]; What will happen if the following code is executed? int[15] = 20;

a. The value will be added to the array.
b. You will get an ArrayIndexOutOfBoundsException
c. Nothing will happen
d. The array will grow in size by one and the value will be added to the array.

User Rednaks
by
6.4k points

1 Answer

6 votes

Answer:

You are creating an array "values" which stores 15 integers. And if we will write int[15]=20, we are not following correct syntax. Hence, nothing will happen, and it might however, throw an error that the syntax is wrong.

Step-by-step explanation:

int[15]=20 is a wrong syntax, and hence nothing will happen or computer might throw an error like that not correct syntax is being used. And if we write values[15]=20, It will certainly throw ArrayIndexOutOfBoundsException as the maximum length is fixed to 15 and values[14] and not more than that.

User Philip  Dernovoy
by
6.6k points