We don't define constructors for servlets as Servlets gets Servlet Config from container. Suppose if i define a constructor in Servlets along with init method, will it be called during initialization or whats the behaviour?
Printable View
We don't define constructors for servlets as Servlets gets Servlet Config from container. Suppose if i define a constructor in Servlets along with init method, will it be called during initialization or whats the behaviour?
What happened when you tried?
hai,
we can define only default constructors in servlets to create servlet object along with init method if we use parameterized constructors it will not work.but if we dont call a constructor also by default the complier internally considers default constructor.
but init method internally works as constructor i.e only one time it loads into jvm's memory same as constructor.
suppose if we provide both default and parameterized constructors server considers ony default and cretaes the object.