Monday, 1 April 2013

Array - 4



package net.dharmaraj;

public class Q {
public static void main(String argv[]) {
int anar[] = new int[5];
System.out.println(anar[5]);
}
}



What will happen if you try to compile and run the following code?

1) Error: anar is referenced before it is initialized 
2) null 
3) 0 
4) 5 


Ans :-

OutPut :- 

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at net.dharmaraj.Q.main(Q.java:6)


No comments:

Post a Comment