Greg McCarroll wrote:
> furthermore i also thought that name of the source file
> must be the same as the name of the class or the interface
>
> Is this something that has changed since Java V1.1?
Nope. As far as I know you've always been able to have multiple classes
in a (.java) source file. You can only have one Public one though, all
the rest can't be (i.e they are implicitly private except to other
classes defined within that source file). For example this code
(contained within the file MultClassTest.java) compiles fine
public class MultClassTest
{
public MultClassTest ()
{
OtherClass oc = new OtherClass ();
}
}
class OtherClass
{
public OtherClass () {}
}
to produce MultClassTest.class and OtherClass.class.
Similarly I can also have (in a file called MultClassTest.java)
public class MultClassTest
{
public MultClassTest ()
{
OtherClass oc = new OtherClass ();
}
class OtherClass
{
public OtherClass () {}
}
}
which compiles to MultClassTest.class and MultClassTest$OtherClass.class
Not sure what Aaron means about Global variables. All classes can have
public class variables which are theoretically global (aslong as you
have access to the the instantiated Object). If you want truly global
variables (as in accessible to all classes) you have to instantiate some
class to hold them all and pass that to everything you instantiate but
if you're not doing that you're breaking the (pure) OO model quite badly
anyway. It's a bit of an arse but hey ho ...