If we specify negative number while creating array then what will happen?

class Array4
{
public static void main(String[] args)
{
int[] x=new int[-4];
System.out.println(x);
}
}
/*
Output:- RuntimeException[NegativeArraySizeException]
Explanation:- If we are trying to specify Array size with negative int value
then we wil not get compilation error but we will get runtime exception
*/

0 comments: