This is a question from A Programmer's Guide to
Java Certification by Mughal
class MyClass{
public static void main(
String args[]){
int size = 30;
int[] arr = new int[size];
for(int i=0;i< size;i++){
System.out.println(arr[i]);
}
}
}
a) Code will fail to compile because int array declaration is wrong
b)The program will compile but will throw an IndexArrayOutOfBounds Exception when run.
c)The program will compile and run without error ,but will produce no output
d) The program will compile and run without error and type nos 0 to 19.
e) The program will compile and run without error and type twenty 0s.
f)The program will compile and run without error and type twenty nulls.
The answer given is (e), But isn't array a local variable so by default it should not be initialized to anything?And accessing elements from an uninitialized array should give run time exception.