Open Certification Helper Popup Reset Popup

TOTAL QS = 18Time [ 00 : 00 : 00 ]
00:00:00

Java Exception Handling Basics Online Practice Test 2

Instructions

Total Questions: 18

Total Minutes: 18

This ExamTray Free Online Test or Quiz or Trivia tests your Programming Skills on the basics of Java Exception Handling. This practice test displays answers after finishing the exam for review. You can easily clear Competitive Exams and Job Interview Questions. Students can learn Java basics.

Go through Java Theory Notes on Exception Handling and Java Theory Notes on Try-With-Resource before attempting this test.

All the Best

Challenge SCORE

0 / 18

Take This Exam
1) What is the output of the below Java code with exceptions?
public class ExceptionTest8
{
  public static void main(String[] args) throws ArithmeticException
  {
    System.out.println("I am happy.");
    throw new ArithmeticException();
  }
}
2) What is the output of the Java code with exceptions?
public class ExceptionTest9
{
  public static void main(String[] args)
  {
    System.out.println("I am going to forest.");
    throw new ClassNotFoundException();
  }
}
3) What is the output of the below Java code with exception handling keywords?
public class ExceptionTest10
{
  public static void main(String[] args) throws Exception
  {
    System.out.println("Good Morning Cortana.");
    throw new NoSuchMethodException();
  }
}
4) What are the difference between Checked and Unchecked exceptions in Java?
5) Can you catch an object of type Error in Java using TRY-CATCH blocks?
6) Which is the superclass of Error class in Java?
7) An Error is treated like a _____ type of exception by the compiler.
8) Which is the exception handling block that closes the used resources inside of it automatically in Java?
9) Choose the correct syntax of a try-with-resource in Java.
10) Who closes the resources using code in a TRY-with-resources block in Java?
11) What is the output of the below Java program with Try With Resource block?
import java.io.*;

public class ExceptionTest12
{
  public static void main(String[] args)
  {
    try(BufferedWriter bw = new BufferedWriter(new FileWriter("abc.txt"));)
    {
      System.out.println("Inside Try With Resource block.");
    }
    catch(Exception e)
    {	
    }
  }
}
12) Is it possible to write Java code efficiently without using TRY-WITH-RESOURCE blocks?
13) A try-with-resource supports only the objects of classes to close automatically that implement ___ Interface in Java.
14) What is the output of the below Java program with nested exceptions?
public class ExceptionTest14
{
  public static void main(String[] args)
  {
    try
    {
      int a=10/1;
      try
      {int b=20/1;}
      catch(Exception e1)
      { System.out.println("b=20"); }
    }
    catch(Exception e2)
    {System.out.println("a=10");}
  }
}
15) Choose the right statement about nesting of try-catch-finally in Java?
16) The variables initialized inside a TRY-with-resource are treated like ____ variables in Java.
17) An exception of user-generated-type is treated like a ___ exception.
18) What is the output of the Java code with custom exceptions?
public class ExceptionTest15
{
  void show(int a) throws MyException
  {
    System.out.println("Hello Custom Exception");
    int b = a/0;
  }
  public static void main(String[] args)
  {
    ExceptionTest15 obj = new ExceptionTest15();
    obj.show(5);
    System.out.println("Bye Custom Exception");
  }
}

class MyException extends Exception
{
  MyException(){ super();}
  MyException(String name){ super(name); }
}
Certification Group ID
0