The following compiles and runs:
public class Program
{
public static void main(String[] args)
{
System.out.println("It runs" );
}
}
class Foo
{
public double foo1() { return (1.0);}
}
The following fails with a static error:
class Foo
{
public double foo1() { return (1.0);}
}
public class Program
{
public static void main(String[] args)
{
System.out.println("It runs" );
}
}
I can't find where in the Java language specification the order of classes in a unnamed package is allowed to make a difference.
Thanks
The problem is that we currently pick the class name of the first class defined in the file when we try to figure out what class to run.
I think that was done to simplify programming for beginners, who might want to put several classes in the same file, and who do not have one of them declared as public.
We might want to change our logic to pick the class that is defined as public, and only if there is no public class, then pick the first class. That involves more parsing, though, which unfortunately is inefficient with our current internal representation,