|
INTERVIEW QUESTIONS
J2EE
JSP
DETAILS
Question: Can we use the constructor, instead of init(), to initialize servlet?
Answer: Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.
|
|
|
Category |
JSP Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 6714 users |
Added on |
9/16/2014 |
Views |
71511 |
Rate it! |
|
|
Question:
Can we use the constructor, instead of init(), to initialize servlet?
Answer:
Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All JSP Interview Questions & Answers - Exam Mode /
Learning Mode
|