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.
About Question com.enthuware.ets.scjp.v6.2.645 :
Moderator: admin
Online
-
- Site Admin
- Posts: 10090
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.645 :
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.
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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 16 guests