Here the Answer for the Out of Bound !,
August 30, 2009 at 4:53 AM
package cert;
public class ArrayBound { public static void main(String[] args) { int[] a = new int[5]; a[0] = 2; a[1] = 3; a[2] = 4; a[3] = 5; a[4] = 6; System.out.println(a[5]); }
} In the above code the array can store 5 elements. those are from '0' to '4'. But we tried to get the 5th element which crosses the allocated memory is called out of bound and when you try to run this code you will get the following error.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at cert.ArrayBound.main(ArrayBound.java:10)
View All Comments
| View Tutorial