Basics of Exception Handling in Java

This quiz has basics of Exception Handling questions

14 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What would be the output of the following program?

Class A {
 public static void main(String args[]) {
  int a = 0;
  int b = 10 / a;
 }
}
  1. 0
  2. 10
  3. Infinite
  4. RuntimeException
  5. Compile Time Exception
Question 2 Multiple Choice (Single Answer)

Which of the following statements is false regarding 'finally' keyword in Java?

  1. Finally block does not get executed in case an exception does not occur.
  2. There can be multiple finally blocks in a Java method.
  3. Finally block is optional.
  4. A try statement without a catch block must be followed by a finally block.
  5. The finally block executes even if no catch block executes.
Question 3 Multiple Choice (Single Answer)

Which of the following is not an unchecked exception?

  1. ArithmeticException
  2. NullPointerException
  3. NumberFormatException
  4. ArrayIndexOutOfBoundsException
  5. IOException
Question 4 Multiple Choice (Single Answer)

Which of the following keywords is not associated with Java exception handling?

  1. try
  2. catch
  3. throw
  4. finally
  5. final
Question 5 Multiple Choice (Single Answer)

Which of the following is responsible for the occurence of exceptions?

  1. Syntactical errors
  2. Symentical errors
  3. Lexical errors
  4. Pass 1 error of the compiler
  5. Program load time error
Question 6 Multiple Choice (Single Answer)

Which of the following Exception classes in Java is used to deal with an exception, where an assignment to an array element is of incompatible type?

  1. ArithmeticException
  2. ArrayIndexOutOfBoundsException
  3. IllegalArgumentException
  4. ArrayStoreException
  5. IllegalStateException
Question 7 Multiple Choice (Single Answer)

Which of the following methods is used in Java to throw an exception explicitly in a program?

  1. Throws
  2. Throw
  3. Finally
  4. None of these
Question 8 Multiple Choice (Single Answer)

Which of the following Exception classes is used to deal with an exception of an attempt to violate the security?

  1. NullPointerException
  2. ClassNotFoundException
  3. IllegalAccessException
  4. InterruptedException
  5. SecurityException
Question 9 Multiple Choice (Single Answer)

Which of the following blocks in Java is executed regardless of whether an exception is thrown or not?

  1. try block
  2. catch block
  3. finally block
  4. final
  5. private
Question 10 Multiple Choice (Single Answer)

Which of the following methods of Throwable class sends the stack trace to the specified stream?

  1. printStackTrace()
  2. fillInStackTrace()
  3. printStackTrace(PrintStream stream)
  4. toString()
  5. getLocalizedMessage()
Question 11 Multiple Choice (Single Answer)

Name the exception thrown by read method of the InputStream class

  1. IOException
  2. ReadException
  3. FileNotFoundException
  4. Exception
  5. All of the above
Question 12 Multiple Choice (Single Answer)

Which of the following is not a Java's checked exception?

  1. ClassNotFoundException
  2. ClassNotSupportedException
  3. InstantiationException
  4. UnsupportedOperationException
  5. NoSuchMethodException
Question 13 Multiple Choice (Single Answer)

Which of the following classes is at the top of Exception class hierarchy?

  1. Exception
  2. Error
  3. Throwable
  4. RuntimeException
  5. IOException
Question 14 Multiple Choice (Single Answer)

Which of the following Exception classes is used when a requested operation is not compatible with the current thread state?

  1. ArithmeticException
  2. IllegalStateException
  3. IllegalThreadStateException
  4. ArrayStoreException
  5. NegativeArraySizeException