Exception in Java MCQs Exercise II

Ques 1 Exception


What is the output of the following Java Code?


class Exception{
 public static void main(String[] args){ 
  try{
    throw 5;
  }
  catch(int ex){
   System.out.println("Exception: " + ex);
   }
 }
} 

A Exception : 5
B Exception : 0
C No output
D Compilation Error

Ques 2 Exception


Which block of code must be used to enclose the code that might throw an exception?

A try
B catch
C finally
D throw

Ques 3 Exception


In a catch block, which parameter allows you to reference the caught exception object?

A error
B e
C exception
D ex

Ques 4 Exception


Which type of exception occurs due to problems that are not caused by the program's logic but by external factors like network issues or file not found?

A Checked exceptions
B Unchecked exceptions
C Runtime exceptions
D IOExceptions

Ques 5 Exception


What is the output of the following Java Code?

try {
    throw new RuntimeException("Custom exception");
} catch (RuntimeException e) {
    System.out.println("RuntimeException: " + e.getMessage());
} catch (Exception e) {
    System.out.println("Exception: " + e.getMessage());
}

A RuntimeException
B Exception
C Custom exception
D Compilation error