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 packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "packages" Watch "packages" New topic
Author

packages

Bob Smithsoon
Greenhorn

Joined: Oct 26, 2005
Posts: 1
I have a file called Class1.java and inside I have 3 classes defined, one is public access the other two are package access, I have another file called class2.java, 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: 686
If "not working" means an error message, post it.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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

javac class2.java

might fail,

javac class1.java class2.java

should work.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: packages