nerdexam
Oracle

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."…

Create Java Web Applications using Servlets

Question

Given the code fragment:

What output will be returned when this servlet is called a GET request?

Exhibit

1Z0-900 question #66 exhibit

Options

  • AService() method called.
  • BService() method called.Get() method called.
  • CAn HTTP error
  • DGET() method called.

How the community answered

(24 responses)
  • A
    96% (23)
  • D
    4% (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 called super.service() or doGet() 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(), not GET(), and it isn't called here at all since service() 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

#servlet lifecycle#HTTP GET handling#service() method#request dispatch

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice