Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ashwini
what is the output?
1 Answer(s)      3 years and 9 months ago
Posted in : Java Interview Questions


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


Advertisement
View Answers

March 14, 2011 at 1:10 PM


It gives ArrayIndexOutOfBoundsException as you haven't add element to array.

Correct Program is:

public class MyAr{
    public static void main(String argv[]) {
        int[] i=new int[5];
        i[0]=1;
        i[1]=2;
        i[2]=3;
        i[3]=4;
        i[4]=5;
        System.out.println(i[4]);
        }
        }


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com