Page 1 of 1

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

Posted: Sat Jun 18, 2011 9:52 pm
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

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

Posted: Sun Jun 19, 2011 6:28 pm
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.

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

Posted: Mon Jun 20, 2011 8:53 am
by Guest
Cool, I didn't know that about the exceptions, only the usual "same or narrower".
Thanks for the prompt reply.

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

Posted: Mon Oct 20, 2014 11:08 am
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.

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

Posted: Mon Oct 20, 2014 8:18 pm
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.

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

Posted: Tue Oct 21, 2014 10:15 am
by bluster
Thanks, I should have grokked that.