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.
- class A3{
- static{
- System.out.println("static block is invoked");
- System.exit(0);
- }
- }
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
Post a Comment