aspose file tools*
The moose likes Servlets and the fly likes Why is HttpServlet an abstract class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why is HttpServlet an abstract class?" Watch "Why is HttpServlet an abstract class?" New topic
Author

Why is HttpServlet an abstract class?

Lucy Smaile
Ranch Hand

Joined: Apr 17, 2002
Posts: 45
OK, maybe this should be in basic Java or something, but I was wondering about it...
You have to override at least one of the doX methods, right? But none of them is abstract, so how can it tell?
I thought the definition of an abstract class was a class with at least one abstract method, which had to be overridden in order to implement the class. Can anyone put me right?
Thanks
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
They do not have to be abstract in order to be able to override them. An abstract is not required to have an abstract method, it's just that any class with an abstract method will have to be declared as abstract.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Alexander Pantaleev
Greenhorn

Joined: Jun 14, 2002
Posts: 5
An abstract class is a class that cannot be instantiated, only extended.
HttpServlet is declared abstract, because there is no sense in using it directly - its methods provide default functionality only (which, in most cases, does nothing). You can add your own functionality by overriding any of those methods in a class that extends HttpServlet.
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055

I thought the definition of an abstract class was a class with at least one abstract method, which had to be overridden in order to implement the class.

No, putting the modifier "abstract" is sufficient to make a class abstract. An abstract class can have some or all its methods implemented, but it cannot be instantiated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is HttpServlet an abstract class?