✏️ Explanatory Question
If a program tries to access an element beyond the array’s size, Java will throw an ArrayIndexOutOfBoundsException.
Example:
public class Example {
public static void main(String[] args) {
int[] ints = new int[50];
ints[60] = 12345; // Error: index 60 doesn’t exist
}
}
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at Example.main(Example.java:4)