whis is the NegativeArraySizeException in java? or define NegativeArraySizeException with exp?
NegativeArraySizeException occurs, when you declare an array of negative size.
Example
public class CloneException implements Cloneable { int num; Integer[] numarray; CloneException(int numelements) { num = numelements; numarray = new Integer[num]; } public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { throw new Error("Exception in the Clone"); } } public static void main(String[] args) { CloneException ex = new CloneException(-1); CloneException copy = (CloneException) ex.clone(); ex.numarray[0] = new Integer(1); System.out.println("numarray[0] = " + ex.numarray[0]); System.out.println("numarray[0] = " + copy.numarray[0]); } }
Ads