Share on Google+Share on Google+

SCJP Module-1 Question-3

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];

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




It compiles but raise runtime exceptions (java.lang.ArrayIndexOutOfBoundsException)


Posted on: July 6, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null