• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why is HttpServlet an abstract class?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic