GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java

 Print  |  
Question:  Exception Handling

Answer: What is the output of the following program, When tested under JDK 5.0

class ExceptionDemo
{
public static void main(String[] args)
{
int a[] = new int[] {1,2,3,4,5};
try{
System.out.prinltln(a[6]);
} catch(Exception e) {
System.out.println("Catching Exception ...");
} catch(ArrayIndexOutofBoundsException ae) {
System.out.println("Catching ArrayIndexOutOfBounds Exception ...");
}
}
}





April 04, 2008 06:37:32 #1
 hemanth_1386   Member Since: April 2008    Total Comments: 3 

RE: Exception Handling
 
It doesn't give any compilation error.. it compiles successfully..
It throws ArrayIndexOutOfBoundException and it is caught by catch (Exception e) as it matches all the exceptions.
     

 

Back To Question