This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "packages" Watch "packages" New topic


Bob Smithsoon

Joined: Oct 26, 2005
Posts: 1
I have a file called and inside I have 3 classes defined, one is public access the other two are package access, I have another file called, how can I access the package access classes in class1 within class2? I tried putting class1 into a package and then importing that package in class2, but its not working, thanks.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 696
If "not working" means an error message, post it.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Hi Bob,

Welcome to JavaRanch!

In general, the idea is that if you have multiple classes in a source file, some of them won't have the same name as the source file, and so they're a little hard for the compiler to find. Therefore, the best plan is to only include multiple classes in a single file if those classes won't be used by other classes in other files, but only by classes in the same file. Otherwise, it just makes life easier for each class to be in its own file, with the file named after the class.

But the technical solution is to compile the multiple source files on the same command line, at the same time; in other words, whereas


might fail,


should work.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: packages
It's not a secret anymore!