Files
javaSE-0113/day05/src/com/inmind/array01/Demo04.java

20 lines
650 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.array01;
/*
.数组的异常_空指针异常
NullPointerException
空指针异常
*/
public class Demo04 {
public static void main(String[] args) {
int[] arr = {1, 2, 3};//省略了new
System.out.println(arr[2]);//3
arr = null;//空常量,它的作用是给引用数据类型初始化的,也就是引用数据类型的默认值
if (arr != null) {//对引用数据类型增加安全性的判断
System.out.println(arr[2]);//如果对应的引用数据类型为null还继续操作就会报NullPointerException
}
System.out.println("程序结束");
}
}