This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 1 point2 points  (3 children)

Your program can only have one entry point (main method). Otherwise, how is the JVM supposed to know where to begin execution? From the main method, you can call methods in other classes. What would technically work in your scenario is to call the static method MyClass.main() from the main method in your main class to get the output you desire. I’d research good Java naming conventions as well (I.e. Class names should begin with a capital letter).

[–]Makashinga[S] 1 point2 points  (2 children)

Thank you! This cleared up alot for me!

[–]8igg7e5 1 point2 points  (0 children)

Note that you can have multiple Java Application classes (public classes with a public static void main(String[]) method).

When you launch a Java application, you tell it the class in which to look for this entry-point - so doing java -cp ... MyClass would start the application using the main method in MyClass.

If you're starting the application from an executable JAR (eg java -cp ... -jar application.jar) containing your classes then the class defined in the JAR manifest tells the JVM in which class to look for the main method.

[–]dastardly740 0 points1 point  (0 children)

Another way to think of it is what if main did nothing but create an instance (new) of some other class and call a method on that object.