Java Exception Handling Quiz

A quiz covering Java exception handling, applets, and core Java programming concepts

20 Questions Published

Questions

Question 1 Multiple Choice (Multiple Answers)

Identify the true statements.

  1. Checked exceptions must be explicitly caught or propagated(declared Thrown)
  2. Unchecked exceptions must be explicitly caught or propagated(declared Thrown)
  3. Checked exceptions in Java extend the java.lang.Exception class
  4. Unchecked exceptions extend the java.lang.RuntimeException class
Question 2 True/False

By convention, all exception-class names should end with the word Exception

  1. True
  2. False
Question 3 True/False

Java guarantees that a finally clause (if one is present) will execute even if a try block exits by using a return, break or continue statement.

  1. True
  2. False
Question 4 Multiple Choice (Single Answer)

From which problems is it possible for a program to recover?

  1. Errors
  2. Exceptions
  3. Both errors and exceptions
  4. Neither
Question 5 Multiple Choice (Single Answer)

Is a program required to catch all exceptions that might happen?

  1. No. You can write a program to catch just the exceptions you want.
  2. No. But if a program catches one type of exception it must catch all other types as well.
  3. Yes. If a program is not written to catch all exceptions it will not compile.
  4. Yes. A program can not do I/O unless it catches all exceptions.
Question 6 True/False

Class Exception is the superclass of all exceptions

  1. True
  2. False
Question 7 Multiple Choice (Single Answer)

Java throws ------------------- when division by zero in integer arithmetic occurs

  1. an IntegerArithmeticException
  2. an ArithmeticException
  3. a DivideByZeroException
  4. a NumberFormatException
Question 8 True/False

A try block must always be followed by one or more catch blocks

  1. True
  2. False
Question 9 True/False

If a catch handler is written to catch exception objects of a superclass type, it can also catch all objects of that class's subclasses.

  1. True
  2. False
Question 10 Multiple Choice (Single Answer)

What type of exception is thrown by parseInt() if it gets illegal data?

  1. ArithmeticException
  2. RunTimeException
  3. NumberFormatException
  4. NumberError
Question 11 True/False

Is this Legal? Class ExceptionA extends Exception {} class ExceptionB extends ExceptionA {} public class Test{ void thrower() throws ExceptionA{ throw new ExceptionA(); } public static void main(String[] args){ Test t = new Test(); try{t.thrower();} catch(ExceptionB e) {} } }

  1. True
  2. False
Question 12 Multiple Choice (Single Answer)

Which statement is FALSE about the try{} block?

  1. Some of the statements in a try{} block will never throw an exception.
  2. The statements in a try{} block may throw several types of exception.
  3. The try{} block can not contain loops or branches.
  4. The try{} block must appear before the catch{} blocks.
Question 13 Multiple Choice (Single Answer)

Which statement is FALSE about catch{} blocks?

  1. There can be several catch{} blocks in a try/catch structure.
  2. The catch{} block for a child exception class must PRECEED that of a parent execption class.
  3. The catch{} block for a child exception class must FOLLOW that of a parent execption class.
  4. If there is no catch{} block there must be a finally{} block.
Question 14 Multiple Choice (Single Answer)

What happens in a method if an exception is thrown in a try{} block and there is NO MATCHING catch{} block?

  1. This is not legal, so the program will not compile.
  2. The method throws the exception to its caller if there were no matching catch{} block.
  3. The program halts immediately.
  4. The program ignores the exception.
Question 15 Multiple Choice (Single Answer)

How many finally{} blocks may there be in a try/catch structure?

  1. There must always be one, following the last catch{} block.
  2. There can be zero or one immediately after each catch{} block.
  3. There can be zero or one, following the last catch{} block.
  4. There can be any number, following the last catch{} block.
Question 16 Multiple Choice (Single Answer)

When is a finally{} block executed?

  1. Only when an unhandled exception is thrown in a try{} block.
  2. Only when any exception is thrown in a try{} block.
  3. Always after execution has left a try{} block, no matter for what reason.
  4. Always just as a method is about to finish.
Question 17 Multiple Choice (Single Answer)

What is Java (in regard to Computer Science) ?

  1. A type of coffee
  2. An object-oriented programming language
  3. An interactive website
  4. None of the above
Question 18 Multiple Choice (Single Answer)

What is an Applet ?

  1. Type of computer
  2. A Java program that is run through a web browser
  3. An interactive website
  4. A type of fruit
Question 19 Multiple Choice (Single Answer)

Java runs on _______.

  1. Windows
  2. Unix/Linux
  3. Mac
  4. All of the Above
Question 20 Multiple Choice (Single Answer)

Why can't the whole program just consist of the one line that does the painting ?

  1. In Java, to create an applet, you can't call on functions without defining a class to call them.
  2. To appear on the web, Java must use an applet, and without first defining a class, you won't be painting onto anything.
  3. The drawString function is not defined without the "import" statements at the top.
  4. All of the above.