Java Exception Handling TRY CATCH FINALLY MCQ Questions and Answers 1

Study and learn Interview MCQ Questions and Answers on Java Exception Handling with TRY, CATCH and FINALLY blocks. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes on Exception Handling before reading these objective questions.



1) What is an Exception in Java?
A) An exception is like a generic error error occurring during the time of execution of program
B) An exception may occur due to memory or hardware issues
C) An exception leads to bad experience for an End user of the software
D) All the above
Answer [=]
Answer[=]
2) All Java exceptions can be handled gracefully. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
3) Are the classes Error and Exception similar in Java?
A) No
B) YES
C) -
D) -
Answer [=]
Answer[=]
4) Which is the super class in Java that bundles all classes to deal with exceptions and errors?
A) Error
B) Exception
C) Throwable
D) Throw
Answer [=]
Answer[=]
5) Which are the keywords used to handle exceptions in Java?
A) TRY, CATCH
B) FINALLY
C) THROW, THROWS
D) All the above
Answer [=]
Answer[=]
6) Where should you keep your Java code for checking against runtime exceptions?
A) Inside TRY block
B) Inside CATCH block
C) inside FINALLY block
D) All the above
Answer [=]
Answer[=]
7) Where should you keep your Java code that helps to take action on the exceptions raised inside TRY block?
A) One more TRY block
B) CATCH block
C) FINALLY block
D) None of the above
Answer [=]
Answer[=]


 

8) What is the output of the below Java code with Exceptions?
public class ExceptionTest1
{
  public static void main(String[] args)
  {
    try
    {
      int a=9, b=0;
      int c = a/b;
      System.out.println("Exception occurred.");
    }
    catch(Exception e)
    {
      System.out.println("Catching an Exception.");
    }
  }
}
A)
Exception occurred.
Catching an Exception.
B)
Exception occurred.
C)
Catching an Exception.
D) No output
Answer [=]
Answer[=]
9) If an exception occurs, all the lines of Java code that is below it stops executing. State TRUE or FALSE. 
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
10) Java exceptions are handled by ____.
A) Java Compiler
B) Java Runtime
C) -
D) -
Answer [=]
Answer[=]
11) Can you add more than one CATCH block when handling exceptions in Java?
A) YES
B) NO
C) -
D) -
Answer [=]
Answer[=]
12) A TRY block is the reason for generating a manual exception or an unexpected Runtime exception. State TRUE or FALSE. 
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
13) What is the output of the below Java code with Exceptions?
public class ExceptionTest2
{
  public static void main(String[] args)
  {
    try
    {
      int ary[] = {10, 20, 30};
      int tempt = ary[4];
    }
    catch(ArrayIndexOutOfBoundsException e1)
    {
      System.out.println(e1.getMessage());
    }
    catch(Exception e2)
    {
      System.out.println("Some exception");
    }
  }
}
A)
Index 4 out of bounds for length 3
B)
Index 4 out of bounds for length
Some exception
C)
Some exception
D) No exception occurs
Answer [=]
Answer[=]
14) Choose the correct way of writing multiple CATCH blocks in Java.
A)
try {
  int num = 10/0;	
}
catch(Exception e1)
{
  System.out.println("EXCEPTION");
}
catch(ArithmeticException e2)
{
  System.out.println("ARITHMETIC EXCEPTION");
}
B)
try {
  int num = 10/0;	
}
catch(ArithmeticException e2)
{
  System.out.println("ARITHMETIC EXCEPTION");
}
catch(Exception e1)
{
  System.out.println("EXCEPTION");
}
C) -
D) -
Answer [=]
Answer[=]


 

15) Where do you keep the Java code that should be executed at all times even if an exception occurs?
A) inside TRY block
B) inside CATCH block
C) inside FINALLY block
D) All the above
Answer [=]
Answer[=]
16) What is the output of the below java code with exception handling blocks?
public class ExceptionTest4
{
  public static void main(String[] args)
  {
    try
    {
    }
    catch(Exception e)
    {
    }
    finally
    {
      System.out.println("FINALLY block executed");
    }
  }
}
A) No output
B) FINALLY block executed
C) Compiler error
D) None
Answer [=]
Answer[=]
17) What is the output of the below Java code with exception handling blocks?
public class ExceptionTest5
{
  public static void main(String[] args)
  {
    int ary[] = new int[2];
    ary[10] = 5;
    try
    {
      int number= 2/0;
    }
    catch(Exception e)
    {
      System.out.println("Divide by Zero");
    }
    finally
    {
      System.out.println("Inside FINALLY block");
    }
  }
}
A) Inside FINALLY block
B)
Divide by Zero
Inside FINALLY block
C) Compiler error
D) No output
Answer [=]
Answer[=]
18) What is the output of the Java code with FINALLY block and RETURN statement?
public class ExceptionTest6
{
  static void show()
  {
    try
    {
    System.out.println("inside TRY");
    return;
    }
    finally
    {
    System.out.println("inside FINALLY");
    }
  }
  public static void main(String[] args)
  {
    show();
  }
}
A)
inside TRY
B)
inside TRY
inside FINALLY
C)
inside FINALLY
D) Compiler error
Answer [=]
Answer[=]
19) Choose the correct way of writing TRY CATCH FINALLY blocks in Java.
A)
try{}
catch{}
finally{}
B)
try{}
finally{}
C)
try{}
catch{}
D) All the above
Answer [=]
Answer[=]
20) The FINALLY block should always be accompanied by a ___ block in Java.
A) TRY
B) CATCH
C) FINALLY
D) None
Answer [=]
Answer[=]
21) The CATCH block should always be accompanied by a ____ block in Java.
A) TRY
B) CATCH
C) FINALLY
D) None
Answer [=]
Answer[=]


 

22) How many extra TRY blocks may be present with an existing TRY block in Java?
A) 0
B) 1
C) 2
D) 3
Answer [=]
Answer[=]
23) How many CATCH blocks may be present in try-catch-finally series of blocks in Java?
A) 1
B) 2
C) 3
D) any number of catch blocks
Answer [=]
Answer[=]
24) What is an Unchecked Exception in Java?
A) An exception that need not be handled
B) An exception that may be declared without compiler error
C) Exceptions which will ignored by the compiler for not catching or for throwing
D) All the above
Answer [=]
Answer[=]
25) What is a Checked Exception in Java?
A) An exception which should be thrown inside the method along with declaring that the method throws it.
B) An exception which should be handled using TRY CATCH statements.
C) Exceptions for which the compiler throws error without completing compilation for not handling properly
D) All the above
Answer [=]
Answer[=]
26) Choose which are Java unchecked exceptions below?
A) NullPointerException, ArithmeticException
B) IndexOutOfBoundException, ArrayIndexOutOfBoundsException
C) IllegalArgumentException, StringIndexOutOfBoundsException
D) All the above
Answer [=]
Answer[=]
27) Choose which are Java checked exceptions below?
A) ClassNotFoundException
B) NoSuchMethodException, NoSuchFieldException
C) InterrruptedException, IllegalAccessException
D) All the above
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.