static block in java,we can execute a program without main() method

Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)

971

Program:

 class OnlyStaticBlock{

  static{
  System.out.println("static block is invoked");   
  }

}

Output:

depend ok jdk version :
static block is invoked

Error: Main method not found in class OnlyStaticBlock, please define the main method as:
   public static void main(String[] args)
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.