File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes abstract HttpServlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "abstract HttpServlet?" Watch "abstract HttpServlet?" New topic
Author

abstract HttpServlet?

Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Hi,
Can anyone please explain me why the HttpServlet class defined in javax.servlet.http package is an abstract class. GenericServlet is an abstract class as it implements Servlet interface and thus inherits init(ServletConfig) method from it. Since it does not override init(Config) method and provide its body so it has to be an abstract class. GenericServlet class overloads init method and it also defines its body.

HttpServlet does not directly implement Servlet interface. All the methods which it inherits from GenericServlet is not abstract. So it must be a concrete class.

The only reason which I can think of is just to prevent direct instantiation of HttpServlet. Is there any other reason behind it.

Thanks & Regards

Naseem
[ July 08, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29253
    
139

Naseem,
It wouldn't make sense to directly instantiate a HttpServlet class as it wouldn't do anything.

One of the doXXX methods needs to be implemented to provide functionality. The reason the class isn't abstract is so you aren't forced to implement all the doXXX methods. Basically, it provides dummy implementations for you.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Thanks Jeanne.

I got your point.

Regards

Naseem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract HttpServlet?
 
Similar Threads
Basic Servlet Doubt
who provides functionality....
Constructor of Servlet
Why is ServletConfig obj passed to init() of GenericServlet when the class implements the interface?
init() and init(ServletConfig) doubt?