Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why HTTPServlet class is abstract?

 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 308
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 4567
8
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic