File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Query: When should the main class be declared as public & When should a class be declared as public? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query: When should the main class be declared as public & When should a class be declared as public?" Watch "Query: When should the main class be declared as public & When should a class be declared as public?" New topic
Author

Query: When should the main class be declared as public & When should a class be declared as public?

raul saini
Greenhorn

Joined: May 18, 2010
Posts: 18
Question 1: When should the main class be declared as public?

Ques 2: When should a class be declared as public?

Ques 3: Why we can not declare 2 classes public?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
What's a main class? The main method must be declared public for access, but the class with the main method in may have package-private access as long as it is accessed from inside the same directory. [Probably also protected access if it is an inner class, but I have never tried.]
Classes should be declared public if access from outside their package is required. You can have as many public classes as you like, they only must be in their own files. If you search through JavaRanch, you will find more details, but it has to do with easier access to the code for the compiler.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query: When should the main class be declared as public & When should a class be declared as public?
 
Similar Threads
J2eeCertificate ques
Interesting JCP Ques
doubts in mock exam ques
Ques from Abhilash 'ssite
ques