This site requires JavaScript, please enable it in your browser!
Greenfoot back
Ashima
Ashima wrote ...

2013/8/1

Main() method in my Project

Ashima Ashima

2013/8/1

#
Hello all, I am new to Greenfoot as well as to Java. I have downloaded a project from internet, and it has a large number of .java files and each of them has a main(). I thought that in a project, there can only be one main() method in any of the files. Isn't it so?
Gevater_Tod4711 Gevater_Tod4711

2013/8/1

#
You can have a main method in every class. When you compile your programm to an executable jar file you have to choose one class with a main method which is the first method called when the programm starts.
Ashima Ashima

2013/8/1

#
Thanks for help! But, would that not mean that I am doing something (via the main() method) in every file? I mean I am not just creating classes, but doing something to my project, so in that case, what would be the order of execution of main() methods?
Gevater_Tod4711 Gevater_Tod4711

2013/8/1

#
A main method is only called one time when your application starts. Afterwards the main mehtod is not called (in no class). If you create a new object from a class not the main method but the constructor of the class is called.
You need to login to post a reply.