Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why most classes and interface in servlet package abstract ?

 
moneer mohammed
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please can any one tell me why most classes and interface in servlet package abstract
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is obvious that interfaces must be abstract.

Apart from that, only GenericServlet and HttpServlet classes are abstract (if I am not wrong), so they must be subclassed to create an (HTTP)servlet.

For example, to write a generic servlet, you need only override the abstract service method, because the rest of the methods are already implemented in the GenericServlet class.
 
Bassam Zahid
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces are "rules" so they must be present in specifications implemented by third parties as is the case with servlets and JSP.

Abstract classes let you create your own classes "extending" the abstract functionality. Moreover, they ease the developer by providing dummy method implementations.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic