aspose file tools*
The moose likes Beginning Java and the fly likes doubt about 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 "doubt about public??" Watch "doubt about public??" New topic
Author

doubt about public??

pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
is it mandatory that one class has to be declared public if a particular file has more then one class in a single java file??
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10909
    
  12

I don't beleive so. I think the rule is you cannot have MORE THAN one public class, but you can have 0.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
may i know the reason why is that if there is a single public class in a group of classes in a single java file ,then why we have to name the file as one whose class was declared public?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10909
    
  12

again, i am not 100% sure, but i believe it is to make life easier for the folks who write the JVM.
pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
Thanks Fred
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Originally posted by Fred Rosenberger:
again, i am not 100% sure, but i believe it is to make life easier for the folks who write the JVM.


The folks who write the compiler.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt about public??
 
Similar Threads
Error message concerning public modifier
What's wrong??
One Public Class Per Source File?
"One file has to have one and only one public class", is it right?
more than one public class in a single file