Consider the following code fragment int list new int10 for
Consider the following code fragment: int[] list = new int[10]; for (int i = 0; i
Solution
So, the answer is option D. The code has a runtime error indicating that the array is out of bound.
The reason is: here, at first, the array list of integer is defined as it will have 10 elements. That is fine. So, list.length will be 10 after 1st line.
Inside the for loop, it goes from i=0 to i<=10 so it will iterate 11 times and inside the loop, ith element is initialized with random value. So, it will start from list[0] , then list[1] ... and so on. At last, the loop will have i = 10 then list[10] is there. But, that is not possible as list is defined as size 10 i.e. it will have list[0] to list[9]. That means it is an array index out of bound exception.
Do comment if you need any further input on this. Thank you. :)
![Consider the following code fragment: int[] list = new int[10]; for (int i = 0; i SolutionSo, the answer is option D. The code has a runtime error indicating t Consider the following code fragment: int[] list = new int[10]; for (int i = 0; i SolutionSo, the answer is option D. The code has a runtime error indicating t](/WebImages/36/consider-the-following-code-fragment-int-list-new-int10-for-1109195-1761587710-0.webp)