This code is all in a file called AnotherClass.java. What is the technical term for SomeClass? A colleague of mine and I can't seem to find it anywhere. Bruce Eckel's TiJ uses these types of classes all throughout his book.
Thanks.
Originally posted by Gregg Bolinger:
This code is all in a file called AnotherClass.java. What is the technical term for SomeClass? A colleague of mine and I can't seem to find it anywhere. Bruce Eckel's TiJ uses these types of classes all throughout his book.
Thanks.
Excerpt from �7.6 Top Level Type Declarations:
When packages are stored in a file system (�7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:
* The type is referred to by code in other compilation units of the package in which the type is declared.
* The type is declared public (and therefore is potentially accessible from code in other packages).
This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.
Originally posted by Charles Lyons:
Is there actually a technical term? Correct me if I'm wrong, but isn't this just a way to declare package-private classes without having to write a new .java source file? When compiled, these classes just get turned into the normal .class files, just as though they had been written in separate .java files.
So isn't this 'feature' is more of a convenience for writing lots of associated classes in one file - the package-private classes themselves are just normal classes compiled in the normal way. For that reason, I don't think they have, or need, another name.
This does bring up the other question of why we can't write more than one public class in the same file - just compiling the classes into separate .class files? This would work quite well for some small applications or tightly coupled structures; does anyone know of a good reason as to why this is prohibited?