Select the correct statement(s) among the following:

  1. service() method is invoked by the container once per request.

  2. service() method can be invoked only once.

  3. init() is invoked by the container only once per request.

  4. init() is invoked by the container only once per instance.


Correct Option: A,D

AI Explanation

To answer this question, we need to understand the lifecycle methods in Java servlets.

Option A) A. service() method is invoked by the container once per request. - This option is correct. The service() method in a servlet is called by the container for each request made to the servlet.

Option B) B. service() method can be invoked only once. - This option is incorrect. The service() method can be invoked multiple times, once for each request made to the servlet.

Option C) C. init() is invoked by the container only once per request. - This option is incorrect. The init() method is invoked only once when the servlet is initialized, regardless of the number of requests made.

Option D) D. init() is invoked by the container only once per instance. - This option is correct. The init() method is called by the container only once when the servlet instance is created.

Therefore, the correct statements are A and D.

Find more quizzes: