File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Why should be public? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why should be public?" Watch "Why should be public?" New topic

Why should be public?

Ganesan Ramakrishnan
Ranch Hand

Joined: Mar 18, 2008
Posts: 90
Hi all,

I have the doubt in servlet class declaration, is there any specific reason for declaring servlet class as public??

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Why shouldn't it be public?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

The servlet container should be able to access your servlet class. If it wouldn't be public, the servlet container wouldn't be able to create instances of the servlet.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Why should be public?
It's not a secret anymore!