miscellaneous
Method Overriding and NullPointerException rules.
Scenario:
Superclass method throws NullPointerException (Checked/Unchecked?).
Parent method: void process() throws NullPointerException { ... }
Question:
Can Child override it with void process() throws RuntimeException { ... }?
Answer: Yes.
NullPointerExceptionis a RuntimeException (Unchecked).- If the superclass method throws an unchecked exception, the child can throw any unchecked exception (including
RuntimeExceptionitself, which is a superclass of NPE). - Rules for broader exceptions only apply to Checked Exceptions.