Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is HttpServlet an abstract class?

 
Lucy Smaile
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alexander Pantaleev
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic