This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
It is adviced to override init() method but if you are overriding init(ServletConfig) then we need to call super.init(ServletConfig). Why?
I learned that init() is called in init(ServletConfig) of super class so that it can give servletness to the servlet. If that is the case then we can override any init method and then call super.init() so that the servletness of the servlet is gained.
Originally posted by Atul Sawant: It is adviced to override init() method but if you are overriding init(ServletConfig) then we need to call super.init(ServletConfig). Why?
the important reason to call super.init(ServletConfig) is that it sets the ServletConfig object in the servlet. If you overide init(ServletConfig)without calling super.init(SC) You would not be setting the ServletConfig object.
Thanks Clifton. One more basic question on this. Which method does the container implicitly calls if you have not overrided any init() method from superclass? init() or init(ServletConfig)? [ April 10, 2007: Message edited by: Atul Savant ]
Container calls both the method. It will call init(confi) followed by init(). If you don't override init(), the default implementation will be called and the default implementaion of init() does nothing. The container calls init() from inside init(config) method. [ April 10, 2007: Message edited by: Tridib Samanta ]