DEVFYI - Developer Resource - FYI

What will be the output on executing the following code...

Java Interview Questions and Answers (part 3)


(Continued from previous question...)

409. What will be the output on executing the following code...

What will be the output on executing the following code.
public class MyClass {
public static void main (String args[] ) {
int abc[] = new int [5];
System.out.println(abc[0]);
}
}

A Error array not initialized
B 5
C 0
D Print some junk characters

C.

Here it will not give any compile time or runtime error because we have declared and initialized the array properly. Event if we are not assigning a value to the array, it will always initialized to its defaults. So the array will be initialized with values zero.

(Continued on next question...)

Other Interview Questions