Hi all. I got this question from
www.jdiscuss.com. I am a bit confused.
Question No: 5 (Question ID: 796)
Problem
Consider the following code:
public class WWServlet extends HttpServlet
{
....
}
What methods do you need to implement so that it compiles without any errors?
Options
Select 1 correct option.
A service()
B doService()
C doGet
D all doXXX methods
E No method as HttpServlet has dummy implementations.
Answer E
Reason:
GenericServlet has an abstract service(ServletRequest, ServletResponse)
method. HttpServlet extends GenericServlet and provides a concrete
implementation of the service() method. It also provides the empty
implementation for the doXXX() methods.
But the API says:
Provides an abstract class to be subclassed to create an HTTP
servlet suitable for a Web site. A subclass of HttpServlet must override at
least one method, usually one of these:
doGet, if the servlet supports HTTP GET requests
doPost, for HTTP POST requests
doPut, for HTTP PUT requests
doDelete, for HTTP DELETE requests
init and destroy, to manage resources that are held for the life of the servlet
getServletInfo, which the servlet uses to provide information about itself
Is the answer E because the API is only saying you HAVE to override one
of these to provide functionality, not to allow compilation? I dunno. Can
anyone tell me?