Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q 14 page 61 Authore Charles lyons

 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q which method in the abstract class HttpServlet is abstract and must be overridden?
A)protect void service(HttpServletRequest,HttpServletResponse)
B)protect void doGet(HttpServletRequest,HttpServletResponse)
C)protect void doPost(HttpServletRequest,HttpServletResponse)
D)portected void init()
E) none of the above

Correct answere E

But if i change this question
which method(any of one) in the abstract class HttpServlet is must be overridden?

then correct answere B and C is it right?
please any one confirm me..
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if i change this question
which method(any of one) in the abstract class HttpServlet is must be overridden?
then correct answere B and C is it right?


Well, it's not a must. Of course if you want your servlet to serve GET and POST request then you should.
 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vijitha
One more query.....
what about D option it should be or not please explain me region also

I looking for your positive responces.......

Thanks in advances
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Be careful of typos when you post some code. The access identifier is "protected", not "protect", or "portected")
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what about D option it should be or not


Again it's not a must. But if you have some initialization code for servlet to use (getting a DB connection may be) you will override the no-arg version of init(). You may go through the Servlet spec which has breif explanations on all these methods.
 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Vijitha

sorry for typos problem.....
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To clarify, I'll quote from the explanation of the answers given on p.63:
Correct answer: E.
No methods in HttpServlet are abstract, even though the class is! However, good practise dictates that one of the doXxx() methods be overridden, even though they have default implementations.
Of course you don't have to override any doXxx(), but if you don't it makes the servlet pretty useless... Often you'll override doGet() and sometimes doPost(). As mentioned above, there are cases when you might also want to override init() too.
[ December 05, 2008: Message edited by: Charles Lyons ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic