CodesJava

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{
static{
System.out.println("Hello Test");
System.exit(0);
}

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

Sign Up/ Sign In
Ask a Question


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 hr@codesjava.com.

Development

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

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki