I have a doubt regarding HttpServlet class is an abstract class even though there is not any abstract method in the class , all methods are concrete.
Can class be abstract even if does not have any abstract methods? If yes Whats the use?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the case of
HttpServlet, the point is that servlet programmers typically don’t want their servlet to support all 4 oft the main HTTP methods (POST, GET, PUT, DELETE), so it would be annoying to make thedoGet(),doPost(), etc. methods abstract, since programmers would be forced to implement methods that they don’t need. Therefore,HttpServletprovides a default implementation for all those methods that does nothing except return an error statuscode to the client. Programmers can override the methods they need and not worry about the rest. But actually using theHttpServletclass itself make no sense (since it does nothing useful), so it’sabstract.And there you have a great example for when it can make sense to have an abstract class without any abstract method.