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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 47 guests