Why GenericServlet is an abstract class ?

Showing Answers 1 - 39 of 39 Answers

Kethams

  • Dec 14th, 2006
 

To prevent creating of objects

  Was this answer useful?  Yes

Deepak Sharma

  • Dec 19th, 2006
 

GenericServlet r abstract because no one can instansiate the object and it is a parent class for servlet.

thanx

  Was this answer useful?  Yes

Rahul Gupta

  • Dec 20th, 2006
 

GenericServlet class is abstract because there is a method called service() which is public abstract void. and service() must be override, service() method defines what type of protocol is used for request. another thing is that according to Java specifiation those classes have abstract methods must declared abstract.abstract methods have no body only prototype.

wrushasen dakhane

  • Dec 20th, 2006
 

Also I would like to add one thing that, if in future some body wants to access it with some other protocol type then by extending the class it is quite possible.

  Was this answer useful?  Yes

A.Naresh Kumar Reddy

  • Jan 8th, 2007
 

GenericServlet is a convenient abstract class for defining Servlets. Servlets which need more control than HttpServlet can extend GenericServlet.
To write a generic servlet, you need only override the abstract service method.
For that reason GenericServlet is an abstract class

  Was this answer useful?  Yes

sunil.yadav

  • Jan 31st, 2007
 

According to OOPs concept there has to be some point or abstraction, above which one can extends his/her functionallity as per requirement. GenericServlet provides the common architecture above which one can design his/her servlet as per requirement, henceforth no object creation is allowed for the GenericServlet.

  Was this answer useful?  Yes

A.Naresh Kumar Reddy

  • Mar 8th, 2007
 

GenericServlet is a convenient abstract class for defining Servlets. Servlets which need more control than HttpServlet can extend GenericServlet.

To write a generic servlet, you need only override the abstract service method.

For that reason GenericServlet is an abstract class

  Was this answer useful?  Yes

GenericServlet is an abstract class because its upto the user how he wants it to use the life-cycle methods of the servlet and also the server needs to make sure that all the life cycle methods of the servlets have to be implemented.So if a class is extending GenericServlet it is bound to implement all of its abstract all of its methods.

If we had made GenericServlet a non-abstract class then user is not forced to implement all the life cycle methods.Also there are many protocols so in future an new protocol comes up it has just to override these methods.

Dhruv

  Was this answer useful?  Yes

Avijit Chowdhury

  • Nov 10th, 2011
 

when you are overriding any abstract class, you have to override all the methods of that class.

  Was this answer useful?  Yes

Balakrishna

  • Aug 21st, 2013
 

GenericServlet class implements all methods of Servlet interface except service() method.
If any class cant implements all methods of the interface,that class before we declare a "abstract" keyword and that class becoming an abstract class

  Was this answer useful?  Yes

avijith

  • Mar 23rd, 2015
 

It is not recommonded to override the all methods of abstract class., that is why the the vendors make generic servlet as abstract

  Was this answer useful?  Yes

Chinmay Das

  • Dec 10th, 2015
 

GenericServlet is a Abstract class because, it has two init methods, init(ServletConfig conf) and init().
Here, It uses parameterized init to set the ServeletConfig object whereas the second init() is a abstract method that is internally called from init(ServletConfig conf) which facilitates users to provide their own implemntation by overriding it.

  Was this answer useful?  Yes

Ajay Pandey

  • Dec 13th, 2017
 

GenericServlet class implements Servlet interface but leave the service method without implemented. This is the reason GenericServlet class is declared abstract class because giving implementation to service method inside GenericServlet class doesnt make sense. So any class which extends GenericServlet class must implement service method.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions