1Z0-900 · Question #66
Given the code fragment: What output will be returned when this servlet is called a GET request?
The correct answer is A. Service() method called. Option A is correct because the code fragment likely defines a servlet that overrides the service() method directly rather than doGet(). When a GET request arrives, the servlet container calls service(), which executes its custom body and prints only "Service() method called."…
Question
Given the code fragment:
What output will be returned when this servlet is called a GET request?
Exhibit
Options
- AService() method called.
- BService() method called.Get() method called.
- CAn HTTP error
- DGET() method called.
How the community answered
(24 responses)- A96% (23)
- D4% (1)
Explanation
Option A is correct because the code fragment likely defines a servlet that overrides the service() method directly rather than doGet(). When a GET request arrives, the servlet container calls service(), which executes its custom body and prints only "Service() method called." - it does not automatically delegate to doGet() since service() was fully overridden.
Why the distractors are wrong:
- B is wrong because both outputs would only appear if
service()explicitly calledsuper.service()ordoGet()internally, which it does not in this fragment. - C is wrong because no HTTP error is thrown - the servlet handles the request successfully, just not via the inherited dispatch chain.
- D is wrong on two counts: the standard servlet method name is
doGet(), notGET(), and it isn't called here at all sinceservice()was overridden.
Memory tip: Think of service() as a "bouncer" - if you replace the bouncer entirely (override service()), the VIP doors (doGet(), doPost()) never open unless the new bouncer explicitly opens them. Override doGet() instead when you want GET-specific behavior to remain in the normal dispatch chain.
Topics
Community Discussion
No community discussion yet for this question.
