About Question com.enthuware.ets.scwcd.v5.2.106 :

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scwcd.v5.2.106 :

Post by ETS User »

Hi,

These overrides are not valid since they do not throw the same or subclasses of exceptions. Plus the methods are declared public when they should be protected. Am I wrong? I've seen many questions where the exceptions are not part of the methods signatures and that confuses me although I'm pretty sure they should be there. Am I missing something?

Thanks

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

Re: About Question com.enthuware.ets.scwcd.v5.2.106 :

Post by admin »

Hello,
This is OCPJP stuff :) An overriding method is allowed to have no throws clause because no throws clause is a valid subset of exceptions thrown by the overridden method.
Further, an overriding method can increase the visibility of the overridden protected method by making it public.

So the methods are valid.

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

Guest

Re: About Question com.enthuware.ets.scwcd.v5.2.106 :

Post by Guest »

Cool, I didn't know that about the exceptions, only the usual "same or narrower".
Thanks for the prompt reply.

bluster
Posts: 60
Joined: Wed Apr 23, 2014 6:38 pm
Contact:

Re: About Question com.enthuware.ets.scwcd.v5.2.106 :

Post by bluster »

Second answer states that at least 1 of the methods would be called. Its blue comment says the answer is wrong because "None of its methods will be called for HTTP - HEAD, PUT, and DELETE requests".

Say a http client (cURL, browser) does just that. It issues an HTTP PUT request, to a servlet that has not been preloaded or preinitialized. Would not the servlet be loaded and the init() method be called? Only after the init() method running the lack of a doPut() method would come into play, with the default doPut() method sending an 405 error code back.

The above would make the second answer OK. This seems seconded by question #scwcd.v5.2.293, where a blue comment states "Notice that init() will also be called for the first request to this servlet".

Thanks for an explanation, if possible.

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

Re: About Question com.enthuware.ets.scwcd.v5.2.106 :

Post by admin »

The 2nd option says "For each and every request...". init will not be called for "every" request but only for the first one.

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

bluster
Posts: 60
Joined: Wed Apr 23, 2014 6:38 pm
Contact:

Re: About Question com.enthuware.ets.scwcd.v5.2.106 :

Post by bluster »

Thanks, I should have grokked that.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests