Ask coding questions

← Back to all posts
Run Java program different a different name - other than Main.java
tkamal (3)

Right now it seems Java programs can only run if you have a file name Main.java - if you have other files in the folder with a different name Program.java etc these Java file cannot run?
Is there a way to get over this issue?

Commentshotnewtop
timmy_i_chen (962)

There's no way to change which file is executed; however, you can instantiate other classes in the same directory. E.g. if I have Car.java in the same directory as Main.java I can just do:

Car c = new Car(args);
AideOropeza (0)

@timmy_i_chen that doesn't work for me :(

timmy_i_chen (962)

@AideOropeza Can you link me to a repl where you are trying to do it?