Choose Your Language

Thursday 11 July 2013

How to run java program without main method

public class WithOutMainMethod{
static {
   WithOutMainMethod withOutMainMethod=new WithOutMainMethod();
   System.out.println("inside static block!");
   staticMethod();
   withOutMainMethod.nonStaticMethod();
   System.exit(0);
}
   static  void staticMethod(){
       System.out.println("inside static method!");

   }
   void nonStaticMethod(){
       System.out.println("inside non static method!");

   }
}

output:
inside static block!
inside static method!
inside non static method!

No comments:

Post a Comment