Why cant you have 2 main classes?
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 main.java file runs and not the other file which is called tester2.java. inside tester2.java i have a main but that doesn't run.
does anyone know how i can have both running?
Voters
realTronsi
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
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
Main.java
, and then inSales.java
:For your ease, invite me to your repl and I will fix it for you