Answers for "how to run java program without main method"

2

run a java class without main method

//This is prior to Java 7
class StaticInitializationBlock{
   static{
      System.out.println("class without a main method");
      System.exit(0);
   }
}
Posted by: Guest on July-21-2020
1

Can we execute a program without main() method

Yes, one of the ways to execute the program without the main method is 
 using static block
 
 What if the static modifier is removed from the signature of the main method??
 
 Program compiles. However, at runtime, It throws an error "NoSuchMethodError
Posted by: Guest on November-28-2020

Code answers related to "how to run java program without main method"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language