• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

protected vs public void doGet

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"To do good, you actually have to do something." -- Yvon Chouinard
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic