Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

service ( ) method overriding or overloading?

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When there is a request from a client, the Servlet Container calls
service(ServletRequest req, ServletResponse res) method of HttpServlet class. This method in turn
will call service(HttpServletRequest req, HttpServletResponse res) method of HttpServlet class.
Suppose, we have a user-defined class TestServlet(see code below), which extends HttpServlet, has a method
service(HttpServletRequest req, HttpServletResponse res).
My question is whether service(req,res) method in TestServlet is overriding methodB in HttpServlet class or
an overloading method to the methods methodA and methodB in HttpServlet class?
Any clarification on this matter is appreciated.
Thanks in advance
Thambi
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
since TestServlet is extending HttpServlet, so is override. when subclass has a method which has the same method signature as in the super class, it is override's definition.
in this case, if TestServlet defines its own service(HttpServletRequest, HttpServletResponse) then you need to be careful whether you want your do***() to be called.
[ September 27, 2002: Message edited by: Kyle Tang ]
 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Kyle,
Thanks for your prompt response.
I was thinking as the same way as you explained. I got confused when I followed the discussion on the following
thread
where it says:


Keep in mind too that the service method in the code is overloading the public method it gets from its HttpServlet. The
public method in HttpServlet takes a ServletResponse and a ServletRequest as its parameters not HttpServletResponse and
HttpServletRequest. All the public method does is dispatch the request to the protected method after converting the request
and response objects to Http objects. So, in reality, the method in the code posted will never be called, but the method it
overloads will be, along with the protected method the servlet will inherit from HttpServlet.

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Thambi,
you can override an overloaded method!!
the service method continue overloaded in subclass, after overriding..
hope this help..
alex
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic