NegativeArraySizeException

NegativeArraySizeException

whis is the NegativeArraySizeException in java? or define NegativeArraySizeException with exp?

View Answers

March 28, 2012 at 1:21 PM

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]);
  }
}









Related Tutorials/Questions & Answers:
NegativeArraySizeException
NegativeArraySizeException  whis is the NegativeArraySizeException in java? or define NegativeArraySizeException with exp?   NegativeArraySizeException occurs, when you declare an array of negative size. Example
help in java
help in java  Write an application that prompt the user to enter a number to use as an array size, and then attempt to declare an array using the entered size. Java generates a NegativeArraySizeException if wou attempt to create
Advertisements

Ads