Advertisements
Advertisements
Question
Given:
int n = 0;
int ar[] = new int [n];
ar[0] =25;
System.out.print(" ar0] =“ + ar[0]);
The code will generate ______.
Options
no error
logical error
syntax error
runtime error
MCQ
Fill in the Blanks
Advertisements
Solution
The code will generate runtime error.
Explanation:
The array is created with size 0, so it contains no elements. Attempting to access ar[0] results in an ArrayIndexOutOfBoundsException at runtime because index 0 does not exist.
shaalaa.com
Is there an error in this question or solution?
