wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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: 11167
    
  16

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: 11167
    
  16

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: 24183
    
  34

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
"One file has to have one and only one public class", is it right?
One Public Class Per Source File?
more than one public class in a single file
What's wrong??
Error message concerning public modifier