Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why declare HttpServlet class abstract?

 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the reason for declaring HttpServlet class abstract? There doesn't seems to be any abstract methods.
Thanks.
 
Mikalai Zaikin
Ranch Hand
Posts: 3381
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Because this class is not supposed to be created by user, only Servlet Container can create instances of servlet (it does not make much sense to have servlet object outside servlet container).
And every vendor has it's proprietary implementation of concrete servlet class, which is created inside servlet container.
Cheers !
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
supose you have three classes:
Car, FordFocus,FordF250
suppose you have three guys: A,B, C, each one can have a car:
A.setCar(new FordFocus());
b.setCar(new FordF250());
c.setCar(new Car());//this has no usefull meaning
The point is, Car is so abstract that we can't create cars of this class... The same aplies to HttpServlet, Servlet, GenericServlet... If we could create HttpServlets by just calling one constructor they wouldn't be usefull. Each Servlet MUST be implemented.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!