Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException:

Posted: May 9, 2012 in Java

ArrayIndexOutofBoundsException:

It is the child class of Runtime Exception and it is unchecked, automatically raised by the JVM when ever we are trying to access an array element with out of Range index

Example:

public class Test {

public static void main(String[] args) {

int[] a = {10,20,30};

System.out.println(a[1]);

System.out.println(a[10]);  ———–> ArrayIndexOutofBoundsException bcoz we are accessing out of range index.

}}

Output:

20

Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 10

at com.clarity.test1.main(test1.java:91)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s