Skip to content
Sign upLog in
← Back to Community

Why cant you have 2 main classes?

Profile icon

I am doing Object Orientated design so i am using classes and methods creating y program. i want to be able to have a main that tests one part of my class and i want to have another main to test another part of the class.

when i run my program only the first file runs and not the other file which is called inside i have a main but that doesn't run.

does anyone know how i can have both running?

Profile icon
Profile icon
Profile icon

Main is the starting point of your program, your program either starts at point A or point B, like a human. You can't be at two places at once!

Now, what if you still wanted to run other programs? Like the human analogy, you can just go to point B from point A and then to wherever you want to go. In Java, you can do this as well:;

Put that in your, and then in

import java.util.Scanner; public class Sales{ public static void run(String[] args){ } }

For your ease, invite me to your repl and I will fix it for you

Profile icon

The main class is where the program determines as the starting point of the program from which it'll run. If you have two main classes, it won't know which is the beginning of the program