Home Answers Viewqa Java-Interview-Questions NegativeArraySizeException

 
 


Nagendran
NegativeArraySizeException
1 Answer(s)      a year and 2 months ago
Posted in : Java Interview Questions

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 Pages:
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.