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

Source file and public class

Jiaqi Lin

Joined: Jul 20, 2007
Posts: 2
Hi, while doing the Java Rule Round-Up, I came across a question that says each source file need not have a public class. Can someone provide some examples, cos I am not really sure of what the question is asking.
marc weber

Joined: Aug 31, 2004
Posts: 11343

You can specify a "public" access modifier for a top-level class, which makes it accessible everywhere. If you don't specify an access modifier for a top-level class, then it has default access (restricted to the package). So the following could be a source file that does not contain a public class...

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Source file and public class