The Servlet specification p.231 says that the method signature is protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException. Yet in the HFSJbook all the examples show public void doGet..... So is it public or protected?
What is the correct signature? What will be excepted as right in the exam?
We create our own servlet by extending the HttpServlet and overriding the doGet() or doPost(). When it comes to overriding a method defined in the parent class, the subclass can either have the same method signature defined in the parent class or the access specifer can be in widening manner. i.e., default => protected => public. Hope this helps. Refer Overriding for further details
Only those who will risk going too far can possibly find out how far one can go !!!
Thanks for pointing out the Overriding rule. So if you have a question like this in the exam: Which of the following is the correct full signature of a method of HttpServlet that is called for an HTTP GET request? Must it then be protected?
HttpServlet abstarct class has protected void doGet(HttpServletRequest req,HttpServletResponse resp) which will be called for an HTTP GET request .
In case you extend this class then the modifier of doGet can be both public and protected since the questions asks about the signature in HttpServlet then it should be protected
scjp 1.4<br />scwcd 1.4
The moth suit and wings road is much more exciting than taxes. Or this tiny ad: