The program given below is from Java Arrays. It will trace your knowledge of array.
The program given below is from Java Arrays. It will trace your knowledge of array.Given a sample code:
public class Sample {
public static void main(String args[]){
int[] x = new int[5];
System.out.println(x[5]);
}
}
What will happen when you compile and run the given code?
1) Compile time error
2) Compile and print 0
3) Compile and output of null
4) Compiles but gives Runtime Exception
(4)
It compiles but raise runtime exceptions (java.lang.ArrayIndexOutOfBoundsException)