How do I make multiple classes and name them in java?
JavasLava (0)

Whenever I make 2 classes I sometime's put Main as its both of there names, but then I create an Error, So I obviously rename the second class, but it still only calls the first class, Not the second.

p.s I am also a beginner.

You are viewing a single comment. View All
mwilki7 (193)

The java virtual machine can only pick a single main() to run its main thread. If you want to call both, and have fairly deterministic results, do:

class Main
{
    ....
    public static void main(String args[])
    {
        ....
        class Main2;
        Main2.run();
    }
}

class Main2
{
    ....
    public static void run()
    {
        ....
    }
}