Java Reference
In-Depth Information
Answers to Review Questions
1.
Checked exception and runtime exceptions. There is a third category—errors—but
technically, an error is not an exception. A runtime exception is a child of the Runtime-
Exception class, whereas checked exceptions are child classes of Exception (that do not
also extend RuntimeException).
2.
The object must of type java.lang.Throwable to be thrown using the throw keyword.
3.
False. A try block can be followed by any number of catch blocks, including zero.
4.
Protected code.
5.
True. A finally block always executes, no matter what happens in the try block or any
previous catch blocks.
6.
RuntimeException is a child of Exception, so the RuntimeException catch block is
unreachable code and should appear before the Exception catch block.
7.
The string “Something went wrong.” will be displayed next, followed by “Finally!”,
even though the catch block threw the exception again.
8.
The catch block will be skipped, but the finally block always executes, and the string
“Finally!” will be displayed.
9.
The catch block will be skipped because it is not trying to catch a NullPointerException.
The NullPointerException will therefore be thrown down the call stack, but not before
the finally block executes and the string “Finally!” is displayed.
10.
Checked exceptions. Runtime exceptions are not affected by the Handle or Declare
Rule.
11.
throws.
12.
throw.
13.
True, because IOException is a child of Exception, making it a lesser exception.
14.
False, because Exception is the parent of IOException, making it more of an exception,
which is not allowed in method overriding.
15.
java.lang.Throwable (although most will extend Exception).
16.
RuntimeException. If you extend RuntimeException, the class will be a runtime
exception and therefore not a checked exception.
Search WWH ::




Custom Search