Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

protected vs public void doGet

 
Tony Smith
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the HFSJ I always see public void doGet, but in enthuware, they say it should always be protected void doGet, what is going on? Is it used to be protected, and now it can be public or?
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an example of overriding. A legal method override can change the access modifier of a method to a less restrictive one; so you can change the protected mehthod to a public.

However, the opposite is not allowed since, you can imagine how things would stop working if a superclass declared a public method but the subclass overrode it and made it private.
 
Tony Smith
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry, but that doesn't anwswer the question. I know how standard java syntax work, this is something else. In Enthuware it flat out says public void doGet() is wrong, which is wrong essentially.
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, wasn't sure you were clear on that

Well, I've seen lots on incorrect answers and a couple of incorrect concepts in the Enthuware questions so I guess this is one of them.

I guess it's probably unconventional and something not recommended from the OOP point of view rather than being straight out wrong.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On HttpServlet it is protected. But if you override it in your own servlet class, you are allowed to expand it to public.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic