Easy learning with example program codes

Can we run java class without main() method?

Yes, we can run java class without main() method if we use static initalizer and having System.exit(0); statement at the end. Program will compile and execute.

public class Test{
System.out.println("Hello Test");

But it can be done only upto JAVA 6 version. From Java-7 version the program will compile but not execute.

Java interview questions on main method

Copyright © 2018 CodesJava Protection Status SiteMap