Originally posted by Mohan Panigrahi:
[I replaced A and B with class names and numbered the statements. --Ryan]
Now :
1. Container calls myServlet.init(SC)
2. myServlet.init(SC) calls HttpServlet.init(SC)
3. Probably HttpServlet.init(SC) calls HttpServlet.init(),
4. but in no way can HttpServlet.init(SC) call myServlet.init()
.....do you get my question.....how does the init() method gets called..even in this changed scenario.
Re: Statements 3 & 4
Yes, HttpServlet.init(SC)
can call myservlet.init(); it just calls this.init(). There isn't really one myServlet object and one HttpServlet object. There's just one myServlet object that probably overrides the init() method and uses the version of init(SC) defined in the HttpServlet base class.
Re: Statements 1 & 2
The container makes a new myServlet object and calls init(SC) on it. If you've overridden init(SC) in myServlet, then it calls that version of the method. But if you've done "the right thing" and NOT overridden init(SC), then the HttpServlet version is used, but any reference to "this" in init(SC) refers to the one myServlet object that the container made.
Look
here for more info.
Cool?