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
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 the doGet()
, doPost()
, etc. methods abstract, since programmers would be forced to implement methods that they don't need. Therefore, HttpServlet
provides 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 the HttpServlet
class itself make no sense (since it does nothing useful), so it's abstract
.
And there you have a great example for when it can make sense to have an abstract class without any abstract method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With