Why it is throwing NullPointerException and not
Because your are not initialized the array.
static int x = new int;
Reason for NullPointerException:
Thrown when an application attempts to use null in a case where an
object is required.
- Calling the instance method of a null object.
- Accessing or modifying the field of a null object.
- Taking the length of null as if it were an array.
- Accessing or modifying the slots of null as if it were an
- Throwing null as if it were a Throwable value.
You hit by the bolder point, since the array is