Difficulty: Easy
Correct Answer: 1, 4, 5 and 6
Explanation:
Introduction / Context:
This question checks your knowledge of Java’s Throwable hierarchy and the compile-time rules governing the throw statement. Only objects whose types extend Throwable
may be thrown.
Given Data / Assumptions:
throw
.
Concept / Approach:
The throw statement requires an expression of type Throwable or a subtype. The hierarchy is: Throwable → {Error, Exception}. RuntimeException extends Exception. Neither Event nor a bare Object derives from Throwable, so they cannot be thrown.
Step-by-Step Solution:
Check 1) Error: subclass of Throwable ⇒ allowed.2) Event: not a Throwable ⇒ not allowed.3) Object: root of all objects but not a Throwable ⇒ not allowed.4) Throwable: allowed.5) Exception: allowed.6) RuntimeException: allowed.Hence, the correct set is 1, 4, 5, and 6.
Verification / Alternative check:
Try throw new Object();
in a test program; it fails to compile. Replace with throw new Throwable();
or throw new Error();
and it compiles (with appropriate handling/declaring for checked types).
Why Other Options Are Wrong:
Options A/B/D include non-Throwable types (Event or Object) and are therefore invalid.
Common Pitfalls:
Confusing “any object” with Throwable-only; forgetting that RuntimeException is a subclass of Exception and both are Throwable.
Final Answer:
1, 4, 5 and 6
Discussion & Comments