Can we execute a program without main() method?

Can we execute a program without main() method?
Ans- Yes, one of the way is static block but in previous version of JDK not in JDK 1.7.
  1. class A3{  
  2.   static{  
  3.   System.out.println("static block is invoked");  
  4.   System.exit(0);  
  5.   }  
  6. }  
Output: static block is invoked (if not JDK7)
In JDK7 and above, output will be:
Output: Error: Main method not found in class A3; please define the main method as:

public static void main(String[] args)

Comments

Popular posts from this blog

Handling Dynamic Web Tables Using Selenium WebDriver

Verify Specific Position of an Element

Read it out for TESTNG before going for an iterview