How to Excucte a Program without a Main Method in Java


Here this example will explain how to run a program with no main method in Java.

Source Code

ppackage com.beginner.examples;

public class NomainExample{

     static
    {
        System.out.println("Done!");
        System.exit(0);
        
    }
}

Output:

Done!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments