my dog learned polymorphism
The moose likes Servlets and the fly likes Why HTTPServlet class is abstract? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why HTTPServlet class is abstract?" Watch "Why HTTPServlet class is abstract?" New topic

Why HTTPServlet class is abstract?

Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 141
I have just found that HTTPServlet class doesn't contain any abstract methods but still it is declared as an abstract class. Can anyone please suggest a reason for marking this class as ABSTRACT.
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
Because HttpServlet is not designed to solve all web sites specific problems.

Every java programmer will write she/he's own java concrete servlet for her/his purpose, extending it, and taking advantage from the http protocol facilites, already implemented and ready to use, provided by the superclass HttpServlet.

Hope this helps a bit.

Matthew Brown

Joined: Apr 06, 2010
Posts: 4543

Note that when you extend HttpServlet you need to override one of the doXXX methods (doPost, doGet etc). You don't need to override all of them (and you usually won't). Which means they can't be marked as abstract - if they were, you'd be forced to implement them all. But an unmodified HttpServlet is pretty useless, so it's worth labelling it abstract to emphasis it is not intended to be instantiated.
I agree. Here's the link:
subject: Why HTTPServlet class is abstract?
It's not a secret anymore!