数组角标越界异常
创建数组,赋值3个元素,数组的索引就是0,1,2,没有3索引,因此我们不能访问数组中不存在的索引,程序运行后,将会抛出 ArrayIndexOutOfBoundsException 数组越界异常
访问到了数组中的不存在的脚标时发生
public static void main(String[] args) {
int[] arr = {1,2,3};
Systemoutprintln(arr[3]);
}
空指针异常(NullPointerException)
arr引用没有指向实体,却在操作实体中的元素时。
int[] arr = null;
Systemoutprintln(arr[0]);