pTutorial

New way to learn Programming

Exception Handling Quiz in Java

1. What will be the output of the below program?

import java.io.IOException;  
class ExceptionExample{  
  void a()throws IOException{  
    throw new IOException("undefined error");  
  }  
  void b(){  
    a();  
  }  
  void c(){  
   try{  
    b();  
   }catch(Exception e){
   System.out.println("exception handled");
   }  
  }  
  public static void main(String args[]){  
   ExceptionExample obj=new ExceptionExample();  
   obj.c();  
   System.out.println("Rest of program");  
  }  
}  
A. Run Time Error
B. Compilation Error
C. Exception handled Rest of program
C. None of these

2. What will be the output of the below program?

class ExceptionExample3{  
  public static void main(String args[]){  
   try{  
    int uk[]=new int[5];  
    uk[5]=30/0;  
   }  
   
   catch(ArithmeticException e){
System.out.println("ArithmeticException occurs");
}  
catch(ArrayIndexOutOfBoundsException e){
System.out.println("ArrayIndexOutOfBoundsException occurs");
}  
catch(Exception e){
System.out.println("other exception occurs");
}     
System.out.println("rest of the code...");  
 }  
} 
A. Run Time Error
B. Compilation Error
C. ArithmeticException occurs rest of the code...
C. None of these

See Also


QUOTES OF THE DAY

Each day provides its own gifts.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER