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

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki