About Question enthuware.ocajp.i.v7.2.1049 :

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

Moderator: admin

Post Reply
nmmedina
Posts: 3
Joined: Sat Nov 01, 2014 4:46 pm
Contact:

About Question enthuware.ocajp.i.v7.2.1049 :

Post by nmmedina »

In this question, we're dealing with a user-created 'checked' exception (the parent is 'Exception', not 'RuntimeException').

One of the 2 correct answers (option 'E') is an overriding method without a throws clause. I thought 'checked' exceptions always had to be handled either with a try/catch block (which is not the focus of the question) or by throwing the checked exception. So not throwing anything doesn't seem a good answer. Isn't that so?

Thanks.

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

Re: About Question enthuware.ocajp.i.v7.2.1049 :

Post by admin »

You are not applying the concept correctly. It is true that if a code in a method throws a checked exception, it must either be caught or if the method wants to throw it out of itself, the method must declare it in its throws clause.

However, in this case, we are overriding the method itself. It is ok for an overriding method to specify that it will not throw any checked exception out to the caller. So even though the code in the overridden method may throw a checked exception (and that is why that method has specified it in its throws clause), that code will not even execute once it is overridden. The code written inside the overriding method will execute instead and it is ok for that code to not throw any exception.

I am guessing that you are confused about the concept of overriding. The overriding method does not call the overridden method in any hidden/implicit fashion if that is what you are thinking.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

nmmedina
Posts: 3
Joined: Sat Nov 01, 2014 4:46 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1049 :

Post by nmmedina »

OMG, you're right. For some strange reason, only when dealing with exceptions in overriding methods, my brain would apply the concept of method overriding differently and incorrectly. I wasn't realizing what I was doing. Thanks for pointing it out.

Post Reply

Who is online

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