Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.645 :

Posted: Fri Apr 08, 2011 5:28 am
by ETS User
Why can you override IOExcpetion with NullPointerException and not Exception?

NullPointerException is not a subclass IOExcpetion, but Exception is.

Here is the question:

Which of the following exceptions can be declared in the throws clause of a method overriding the method:

public void perform_work( ) throws IOException {...}

IOException

Exception

NullPointerException

No throws clause

Any Subclass of IOException


Right answer, according to the application: IOException, NullPointerException, No throws clause, Any Subclass of IOException.

Re: About Question com.enthuware.ets.scjp.v6.2.645 :

Posted: Fri Apr 08, 2011 6:24 am
by admin
Exception is not a subclass of IOException. IOException is a subclass of Exception. The overriding method can declare any subset of the exceptions (of SubClasses of exceptions) declared in the overridden method.

NullPointerException is a RuntimeException. RuntimeExceptions are not required to be specified in the throws clause but any method can specify them. They do not affect the method signature.