class Test {
publicstaticint num = 0;
publicint num1 = 0;
publicstaticvoidiAmStaticMethod() {
System.out
.println("I am static method, can be called by null reference");
}
publicvoidiAmNonStaticMethod() {
System.out
.println("I am NON static method, don't date to call me by null");
}
}
publicclass Main1 {
publicstaticvoidmain(String[] args) {
Test myObject = null;
// myObject.iAmStaticMethod();// myObject.iAmNonStaticMethod();
Integer i = null;
int num = i;// 自动拆箱的时候会报错Exception in thread "main"// java.lang.NullPointerException at// Main1.main(Main1.java:22)
System.out.println(num);
Test test = null;
System.out.println(test.num1);//NullPointer
System.out.println(test.num);
Map<Integer,Integer> map=new HashMap<>();
int[] numbers = {3, 5, 7,9, 11, 13, 17, 19, 2, 3, 5, 33, 12, 5};
for(int k : numbers){
int count = map.get(k);// NullPointerException here
System.out.println(count);//
map.put(k, count++);
}
}
}